Forking one of your own Github repositories ought to be easy, right? After all, forking somebody else’s repo is as simple as clicking a single button! Surely you can just press that same button on your own repo?
If you press the Fork button on your own repo, the page will refresh and… that’s it. No error message, no suggested course of action, nothing. It turns out forking your own repo on Github is impossible, but don’t worry: following the steps below will get you the next best thing.
1. Create a New Repo On Github
First, go to github.com and create a new repository. This will contain our fork when we’re done. I’ll refer to this repo as “fork-repo”, with the original being “orig-repo”.
Make sure you don’t check the box for “Initialize this repository with a README”. You’ll see why in Step 4!
2. Clone the New Repo Locally
Next, make a local copy of the blank repo we just made. In Terminal, cd to the base directory you want to keep the fork in and then type the following:
git clone https://github.com/YourUsernameHere/fork-repo.git
3. Add an Upstream Remote
We’ll now add an upstream remote pointing at the original repo. This will allow us to pull files from the original repo, both now and in the future if we wish. Make sure you navigate to the directory you cloned the fork repo into first!
cd fork-repo git remote add upstream https://github.com/YourUsernameHere/orig-repo.git
4. Pull From the Original Repo
Now we can pull all the files from our original repo into the fork, like so:
git pull upstream master
Your fork directory should now be identical to your original repo!
Note that if you made a README.md for the new repo (or added any other file) you may have some merge conflicts to resolve before you can go to the next step. Make the necessary changes to your files and commit to resolve the conflict.
You’re done! Well, locally at least. All that’s left is to push your new fork repo back up to Github:
git push origin master