Github: how to fork after cloning?

First rename the old remote as upstream, in case you want to be able to keep in sync with the original repository.

git remote rename origin upstream

Then add your forked repository as origin:

git remote add origin https://github.com/<your-username>/<your-project>

Or if you're using ssh:

git remote add origin [email protected]:<your-username>/<your-project>.git

To push to your repository:

git push -u origin master

To pull from the base repository:

git pull upstream

I recommend you do all of your work in a separate branch, not the master branch. It will be easier to rebase to the upstream/master branch in case you want to make a pull request.

You don't really have to rename the origin to upstream - the remote names can be arbitrary, however I recommended you to do so to keep up with the naming convention used by GitHub.


On the github webpage create a fork in the usual way. Then go to your repository and add a remote which points to your fork: git remote add myfork [email protected]:you/your-fork.git. This adds a remote called "myfork" which you can push to. You could also change the url of the "origin" fork; this will get you exactly the same state as if you had cloned from your fork to begin with: git remote set-url origin [email protected]:you/your-fork.git.

Tags:

Git

Github