I was a little surprised to discover that GitHub doesn’t allow you to fork your own projects as simply as you can fork someone else’s (if you don’t believe me, check out this post). Fortunately it’s pretty simple as long as you can come up with a different name for your new project.
Let’s assume we have an existing project called ‘foo’ and we want to create a fork called ‘bar’.
First, create a new project on GitHub called ‘bar’.
Next, clone foo using the name ‘bar’:
$ git clone firstname.lastname@example.org:YOURNAME/foo.git bar Initialized empty Git repository in /projects/bar/.git/ remote: Counting objects: 3618, done. remote: Compressing objects: 100% (1503/1503), done. remote: Total 3618 (delta 2629), reused 2922 (delta 2075) Receiving objects: 100% (3618/3618), 7.31 MiB | 1.23 MiB/s, done. Resolving deltas: 100% (2629/2629), done.
Next, edit your Git config file and replace the origin URL with your new URL:
$ cd bar $ vim .git/config [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = email@example.com:YOURNAME/bar.git #replace foo with bar
Optionally add your original repo as an upstream source:
$ git remote add upstream firstname.lastname@example.org:YOURNAME/foo.git
Finally, push your new repository up to GitHub:
$ git push -u origin master Counting objects: 3618, done. Delta compression using up to 2 threads. Compressing objects: 100% (949/949), done. Writing objects: 100% (3618/3618), 7.31 MiB | 646 KiB/s, done. Total 3618 (delta 2629), reused 3618 (delta 2629) To email@example.com:YOURNAME/bar.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
Now you can push/pull from your new repo (bar) as expected. You should also be able to merge upstream changes using the following command (although I haven’t tried this yet):
$ git fetch upstream $ git merge upstream/master
And that’s really all there is to it. :-)