git – keeping a fork in sync

Commands to keep a fork in sync with the upstream repo

To keep it up to date with the original source repo (the one you forked it from):

git remote add <your local name for the upstream> <URL for the upstream repo>

To check you set the remote repo as the upstream for your fork:

git remote -v

To check which branch you are working on locally:

git status

Pull changes from the upstream branch:

git pull <your local name for the upstream> <local branch name>

If you accidentally specify the incorrect URL for the remote upstream you forked you can change it by doing the following (as seen when using git remote -v):

git remote set-url <your local name for the upstream> <correct URL for the upstream repo>

At this point you have pulled all changes from the remote upstream repo locally to your machine.  You then need to push these changes to your remote fork on github:

git push



Leave a Reply