Skip to content

Instantly share code, notes, and snippets.

@xenogew
Last active March 22, 2018 01:56
Show Gist options
  • Save xenogew/59e4dcfb475070aa7456c763c1993f4d to your computer and use it in GitHub Desktop.
Save xenogew/59e4dcfb475070aa7456c763c1993f4d to your computer and use it in GitHub Desktop.
The method on how-to update your forked repository with the master repository you forked from.

1. Add the remote called upstream to your own forked repository.

git remote add upstream https://the-git-repo-url.com/whoseever/whatever.git

2. Fetch all the branches from that upstream remote repository to remote-tracking.

git fetch upstream

3. Make sure that your local repository is checkout as the master branch.

git checkout master

4. Rewrite your own forked repository with the upstream/master with rebase or merge, which determine between the effect of the rewriting.

  • If you want your source tree as clean as possible and put the commits that aren't updated with upstream/master yet to the top of it, use
git rebase upstream/master
  • If you don't want to rewrite history of your master branch because other people might have cloned it or whatever, use
git merge upstream/master

If you have rebased your branch onto upstream/master, you may need to force the push in order to push it into your own forked repository.

git push -f origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment