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 [email protected]:YOURNAME/foo.git bar
$ cd bar
Next, edit your Git config file and replace the origin URL with your new URL:
$ vim .git/config
Add your original repo as an upstream source:
$ git remote add upstream [email protected]:YOURNAME/foo.git
Finally, push your new repository up to GitHub:
$ git push -u origin master
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:
$ git fetch upstream
$ git merge upstream/master