While forking your own repo sounds like it should be fairly obvious, its definitely not.

I searched around a bit and found a bunch of circular references to other posts about how to do it, and none were very clear. So I’m posting this to try to make it as clear as possible how to fork your own repo (and its quite easy actually).

Create a new blank repo

First, create a new blank repo that you want to ultimately be a fork of your existing repo. We will call this new repo “forkedrepo”.

Clone that new repo on your local machine

Next, make a clone of that new blank repo on your machine:

[sourcecode light=”true”]

$ git clone https://github.com/YOURUSERNAME/forkedrepo.git

[/sourcecode]

Add an upstream remote to your original repo

While this technically isn’t forking, its basically the same thing. What you want to do is add a remote upstream to this new empty repo that points to your original repo you want to fork:

[sourcecode light=”true”]

$ git remote add upstream https://github.com/YOURUSERNAME/originalrepo.git

[/sourcecode]

Pull down a copy of the original repo to your new repo

The last step is to pull down a complete copy of the original repo:

[sourcecode light=”true”]

$ git fetch upstream

$ git merge upstream/master

[/sourcecode]

Or, an easier way:

[sourcecode light=”true”]

$ git pull upstream master

[/sourcecode]

Now, you can work on your new repo to your hearts content. If any changes are made to the original repo, simply execute a git pull upstream master and your new repo will receive the updates that were made to the original!

Psst: Don’t forget to upload the fresh copy of your new repo back up to git:

[sourcecode light=”true”]

$ git push origin master

[/sourcecode]