281

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.

10
  • 5
    What exactly are you trying to achieve? Maybe you can solve it by just branching?
    – Artefact2
    Jun 9, 2012 at 19:40
  • 11
    I 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 9, 2012 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 9, 2012 at 21:04
  • 1
    @Artefact2 Did you get my questions?
    – WowBow
    Jun 9, 2012 at 21:52
  • 7
    The 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, 2016 at 7:57

14 Answers 14

315

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"

https://help.github.com/assets/images/help/importer/import-repository.png

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.

22
  • 1
    I 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, 2012 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 git-scm.com/docs/git-remote
    – VonC
    Jun 10, 2012 at 22:10
  • 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, 2015 at 17:05
  • 1
    @aus that is expected, for you to fetch from upstream. See stackoverflow.com/a/33360766/6309
    – VonC
    Mar 2, 2016 at 21:21
  • 4
    I 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, 2017 at 16:04
196

A super easy way to do it in 30 seconds from the GitHub website:

  1. 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.
  2. Click the + icon in the top right corner.
    https://i.stack.imgur.com/9zJgo.png
  3. Select "Import repository".
  4. Where it asks for the "Old URL", paste the URL you copied at step #1
    https://i.stack.imgur.com/vgWd3.png
  5. Enter the name of your new repo and click Begin Import.
  6. 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.

0
21

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.

3
  • 7
    This 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. Feb 27, 2022 at 18:08
  • 1
    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, 2023 at 18:39
  • 100% works, thx u !
    – ERJAN
    Oct 2, 2023 at 20:48
16

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

0
10
  1. git clone https://github.com/YOURREPO.git TargetRepoName
  2. cd TargetRepoName/
  3. git remote set-url origin https://github.com/TargetRepoName.git
  4. git push -u origin master
2
  • 2
    One might add that you need to create github.com/TargetRepoName.git before on GitHub, but except that, this answer was my first choice and it worked. Sep 15, 2016 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. Oct 28, 2021 at 6:39
5

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:

Fork own repo via import-1

Fork own repo via import-2

4

Just clone it, create new blank repo, and push to it.

4
  • I cloned it to my local machine and created a blank repo but, when I try to git origin github.com/userName/New_Repo.git .. it says remote origin already exists. How should I solve that?
    – WowBow
    Jun 9, 2012 at 20:56
  • 1
    And now when I push it is changing the original repo.
    – WowBow
    Jun 9, 2012 at 21:01
  • 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 9, 2012 at 22:29
  • 6
    You 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, 2012 at 16:13
1

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.

1

The accepted solution of VonC, unfortunately, did not work for me as I got

remote: Repository not found

What did work was the following:

  1. Create a new_repo at github
  2. git clone new_repo
  3. cd new_repo
  4. git remote add upstream old_repo.git
  5. git pull upstream master
  6. git push origin master

I got all the above from here.

1

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.

  1. Open your own project repo from browser, and download as a zip, eg your-project-master.zip.
  2. Unzip and rename it as your new repo.
  3. Open GitHub Desktop, and add your new repo by browsing it to your unzipped local path new repo. enter image description here
  4. Publish it to your github, by clicking the publish button. Don't forget to add the name and the description :)
1

STEP BY STEP

First you should create an access token

enter image description here

enter image description here

enter image description here

enter image description here

Then:

Import your existing repository

enter image description here

Here:

Enter a name for your new repository

enter image description here

Now the important step

In the password block, you have to enter the access token that you generated

enter image description here

1
  • 1
    Sure, on that way you get a linked history, but I think you wont have the github fork options (compare and Pull-requests between both repos)
    – Radon8472
    Feb 29 at 8:12
0

Just tried this, and it worked:

  1. Fork your repo into an organization account
  2. Rename it
  3. Transfer ownership back to yourself
2
-1

When you create a new repo, you can import from another repo with the repo .git url. It took me 30 seconde.

-2
  1. create a new empty repo on github webfrontend
  2. in a clone of the older repo, replace the remote and push:
git remote remove origin
git remote add origin [email protected]: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")

1
  • 1
    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. Feb 27, 2022 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.