I have a public repository on GitHub. I want to replicate/copy it and work on a new project based on this repository, but I don't want to affect how it is now. I tried forking it using the GitHub UI but it didn't do anything.
-
5What exactly are you trying to achieve? Maybe you can solve it by just branching? – Artefact2 Jun 09 '12 at 19:40
-
10I want to get a copy of the project and extend that project to do something else but without affecting original project. That was it. Any ways, its solved. – WowBow Jun 09 '12 at 20:06
-
1@Artefact2 .. Sorry, I thought the solution by mcepl solved my need but, it didnt. After I clone the project using 'git clone', I don't want to point to the original repo but to a new repo on github that i created. How can I achieve that? – WowBow Jun 09 '12 at 21:04
-
1@Artefact2 Did you get my questions? – WowBow Jun 09 '12 at 21:52
-
http://stackoverflow.com/questions/9742677/is-it-possible-to-fork-a-github-repo-that-i-already-own-and-then-save-it-as-a-ne – ellotheth Jun 10 '12 at 00:48
-
possible duplicate of [How can I fork my own GitHub repository?](http://stackoverflow.com/questions/3772684/how-can-i-fork-my-own-github-repository) – random Dec 15 '14 at 02:17
-
4The benefit of fork compared to creating a new repo is that the graphs and network history are linked together. It's a pity that Github don't allow this. – kenchew Oct 15 '16 at 07:57
-
@Artefact2 One repo is a project template, another is a new project that I want to create from the template. – Damian Yerrick Nov 16 '16 at 23:50
-
Fork it with another account, rename that fork and transfer the ownership to your main account – dan1st Dec 19 '19 at 05:53
-
@FredFranz - has the answer to this. Please be very wary of all other answers here. This seems like a recipe for disaster. If you're not sure what the difference is between a fork and clone, you could end up months down the road and realize you can't update or split your code with a clone. Please be sure you don't NEED a fork before attempting any of the other solutions here. – Jamie Marshall Feb 27 '22 at 18:12
14 Answers
I don't think you can fork your own repo.
Clone it and push it to a new repo is good but you need to:
git clone https://github.com/userName/Repo New_Repo
cd New_Repo
git remote set-url origin https://github.com/userName/New_Repo
git remote add upstream https://github.com/userName/Repo
git push origin master
git push --all
(see git push
)
See the all process described at "Fork your own project on GitHub".
Six years later (2016), you now have the GitHub importer which allows you to import a repo from another source... including GitHub.
See "Importing a repository with GitHub Importer"
narf's answer (upvoted) also illustrate that process.
That will allow you to create a new repository and import the full history of the old one into the new one, using its GitHub url.
Again: what you get is a copy, not a real fork: you cannot make pull request from the new repo to the old one.
Again (bis), as stated in the comments by mpersico
, this is not a TRUE FORK.
If I have a foo which is the canonical source repo for an open source project that I want other people to fork and have access to do PR, then I do not want to work in that repo, I want a fork I can use to issue proper PRs against my project.
I have solved this my creating a second account in GitHub and forking to that.

- 1,262,500
- 529
- 4,410
- 5,250
-
-
@WowBow which config file? (beside a `_netrc` one, or other global config Git parameters, as detailed in http://stackoverflow.com/questions/5377703/syncing-with-github/5378094#5378094) The local git config file recording the new remote `origin` is automatically updated by the `git remote add` command. – VonC Jun 10 '12 at 21:40
-
1I was talking about .git/config. Unless you change the origin url, when you say "git remote add ...." , it will reject you because, the origin name already exists. But once I changed the url in the config file it works fine. The article you pointed to me shows that. – WowBow Jun 10 '12 at 22:04
-
7@WowBow if `remote` already exists, then do a `git remote set-url origin https://github.com/userName/New_Repo`. That will change the `.git/config` file for you. See http://git-scm.com/docs/git-remote – VonC Jun 10 '12 at 22:10
-
-
-
I've deleted the directory by now but I ran `git remote set-url origin
` before trying to push – Nick Jul 24 '15 at 21:34 -
@VonC Amazing. A month later I am doing the same thing and stumble upon the same error. This is the output: `MacBook-Pro:rjs nnikolo$ git remote -v origin https://github.com/username/new_repo (fetch) origin https://github.com/username/new_remo (push) upstream https://github.com/username/old_repo (fetch) upstream https://github.com/username/old_repo (push)` So your solution, unfortunately, doesn't work. – Nick Aug 30 '15 at 16:55
-
@Nick Please post this as a new question: more people will be able to help that way. – VonC Aug 30 '15 at 16:56
-
@VonC I am sure some mod will flag it as a duplicate (happened too often to me) - so see no point of doing it. You should, however, amend your answer as it doesn't work. A fast hack to solve the problem is to set up manually the repo - I did it and now I can push. A small mystery is, however, that some local changes seem to not appear in the push. – Nick Aug 30 '15 at 17:04
-
1@Nick No trust me, no duplicate on this one: explain the context, link back to this question and benefit from Stack Overflow instead of burying an issue in the comments. – VonC Aug 30 '15 at 17:05
-
@VonC I just noticed that I posted a solution a month ago as a post - but it is at the very bottom of this SO question so I didn't see it today. Tbh, I see myself my post as a sort of duplicate but, unfortunately, your solution didn't work for me. – Nick Aug 30 '15 at 17:10
-
-
1@aus that is expected, for you to fetch from upstream. See http://stackoverflow.com/a/33360766/6309 – VonC Mar 02 '16 at 21:21
-
-
2I still feel that forking from repo in same organization should be allowed. What if there's a central repository that's generic to everybody and you want to get updates from it all the time and at the same time do specific changes to your forked copy based on your needs? – Prachi Jun 23 '17 at 16:04
-
@Prachi You could make a branch (you can make pull request from a branch to another branch from within the same remote repo) – VonC Jun 23 '17 at 18:41
-
What if the author of the central repo doesnt give you write access so you can't create a branch. all you can do is fork it. – Prachi Jun 26 '17 at 15:17
-
@Prachi In that case, all that remain is a basic clone, and send patch by emails ;) But depending on your "central organization", you can configure a repo hosting server to allow a branch creation per user, for instance with gitolite (http://gitolite.com/gitolite/user/#personal-branches). But for GitHub organizations, that wouldn't be a valid option, of course. – VonC Jun 26 '17 at 15:20
-
1Not the answer. The OP wanted, and I want, a TRUE FORK. If I have a foo which is the canonical source repo for an open source project that I want other people to fork and have access to do PR, then I do not want to work in that repo, I want a fork I can use to issue proper PRs against my project. I have solved this my creating a second account in GitHub and forking to that. – mpersico Mar 21 '19 at 03:35
-
@mpersico Agreed. I have included your comment in the answer for more visibility. – VonC Mar 23 '19 at 16:46
-
@VonC - thank you. Sorry about the apparent anger in that "Not the answer" comment. Just annoys the &@#%@^(()@# out of me that something as simple as a self fork never occurred to anyone at GitHub. Then again, who knows what devs think; I just came across two processes today that send out notification of execution BEFORE running the process so that on a failed process, the user gets a successful notification. Ugh.
– mpersico Jun 05 '19 at 02:42
A super easy way to do it in 30 seconds from the GitHub website:
- Copy your repo's URL. Ex:
https://github.com/YourName/YourOldRepo
(hint: it's the URL when you look at your repo's main page on github. - Click the
+
icon in the top right corner.
- Select "Import repository".
- Where it asks for the "Old URL", paste the URL you copied at step #1
- Enter the name of your new repo and click
Begin Import
. - That's it! You now have a copy of the full repo, with all commit history and branches!
Limitations: It's not actually a real fork. It's a copy of the repo. It won't allow to do pull requests back and forth.

- 1,984
- 1
- 8
- 7
You can now mark the base repository as a template (in Settings, mark it as a Template repository) and on the main page of the repo, click Use this template to create your second repo.
Creating a repository from a template is similar to forking a repository, but there are important differences[1]:
- A new fork includes the entire commit history of the parent repository, while a repository created from a template starts with a single commit.[1]
- Commits to a fork don't appear in your contributions graph, while commits to a repository created from a template do appear in your contribution graph.[1]
- A fork can be a temporary way to contribute code to an existing project, while creating a repository from a template starts a new project quickly.[1]
Github Help: creating a template repository creating a repository from a template

- 902
- 1
- 11
- 11

- 181
- 2
- 8
Although it is not possible to fork your own repo into the same account, it can be done into an self-owned Organization account, which can be easily created for free via the '+' button.
The main advantage of this option is that the new repo is a real fork of the original one, and not just a clone. This means that you can, for example, update changes in the orginal repo into the new one (which is not the case for a cloned repo).
The only disadvantage I see is that the forked repo won't appear under the user profile but under the organization one.

- 529
- 1
- 5
- 15
-
3This is the only answer, that actually answers the question. I can not stress enough that a copy/clone is not a fork. I highly suggest being wary of other answers on this page. – Jamie Marshall Feb 27 '22 at 18:08
-
I tried transfering it back to my account after that with a different name, but github doesn't allow it, gitlab doesn't have this problem – Tofandel Jan 31 '23 at 18:39
- git clone https://github.com/YOURREPO.git TargetRepoName
- cd TargetRepoName/
- git remote set-url origin https://github.com/TargetRepoName.git
- git push -u origin master

- 1,251
- 4
- 22
- 31
-
2One might add that you need to create https://github.com/TargetRepoName.git before on GitHub, but except that, this answer was my first choice and it worked. – Florian Straub Sep 15 '16 at 20:41
-
I received an error `failed to push some refs to {repo}` because it didn't recognize a master branch. I had to fake it with `git checkout -b master` after step 3, then it worked. – Daniel Szabo Oct 28 '21 at 06:39
Simplest way to achieve the desired effect is to create a new repository, then select the import option and supply the URL of the repo you wish to fork.
Images below will help:

- 381
- 3
- 6
Just clone it, create new blank repo, and push to it.

- 2,688
- 1
- 23
- 38
-
1
-
I cloned it to my local machine and created a blank repo but, when I try to git origin https://github.com/userName/New_Repo.git .. it says remote origin already exists. How should I solve that? – WowBow Jun 09 '12 at 20:56
-
1
-
Can you please tell me how to push to the new repo? I did the clone and creating new repo but i couldnt push to the new repo. – WowBow Jun 09 '12 at 22:29
-
6You have to change the remotes. Otherwise, it's going to try to push to the same location. `git remote rm origin` followed by `git remote add origin URL-to-new-repository` – wadesworld Jun 10 '12 at 16:13
STEP BY STEP
First you should create an access token
Then:
Import your existing repository
Here:
Enter a name for your new repository
Now the important step
In the password block, you have to enter the access token that you generated

- 10,098
- 5
- 45
- 45
I followed these official instructions for "Duplicating a repository" and it seemed to work.
https://help.github.com/articles/duplicating-a-repository/
To create a duplicate of a repository without forking, you need to run a special clone command against the original repository and mirror-push to the new one. This works with any git repository, not just ones hosted on GitHub.

- 2,933
- 5
- 27
- 28
The accepted solution of VonC, unfortunately, did not work for me as I got
remote: Repository not found
What did work was the following:
- Create a new_repo at github
- git clone new_repo
- cd new_repo
- git remote add upstream old_repo.git
- git pull upstream master
- git push origin master
I got all the above from here.

- 2,924
- 4
- 36
- 43
For non tech savvy using GitHub, here is one simple solution as an alternative to other great answers above. What you need is just a GitHub Desktop application.
- Open your own project repo from browser, and download as a zip, eg
your-project-master.zip
. - Unzip and rename it as your new repo.
- Open GitHub Desktop, and add your new repo by browsing it to your unzipped local path new repo.
- Publish it to your github, by clicking the publish button. Don't forget to add the name and the description :)

- 468
- 4
- 15
Just tried this, and it worked:
- Fork your repo into an organization account
- Rename it
- Transfer ownership back to yourself

- 149
- 3
-
5Nice idea but I just tried this and got an error: `aspiers already has a repository in the UPSTREAM/NAME network`. – Adam Spiers May 22 '14 at 15:26
-
this is because they now have redirects after you rename or transfer your repos https://github.com/blog/1508-repository-redirects-are-here – shadowbq Jul 18 '17 at 18:39
When you create a new repo, you can import from another repo with the repo .git url. It took me 30 seconde.

- 1,834
- 2
- 19
- 20
- create a new empty repo on github webfrontend
- in a clone of the older repo, replace the remote and push:
git remote remove origin
git remote add origin git@github.com:account/new.git
git branch -M main
git push -u origin main
This combines the answer of @mcepl with the comment of @wadesworld and is very similar to the official solution shown when creating a fresh repository on github (under the headline "…or push an existing repository from the command line")

- 220
- 3
- 8
-
This is downvoted, because what you have achieved here is a normal 'clone' and not a 'fork'. Forks have specific properties that make them useful for specific situations. They are not the same thing. – Jamie Marshall Feb 27 '22 at 17:27