Skip to content

Instantly share code, notes, and snippets.

@protrolium
Last active May 7, 2018 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save protrolium/a22ac8060f5a4557b67e4cd0ecc8213d to your computer and use it in GitHub Desktop.
Save protrolium/a22ac8060f5a4557b67e4cd0ecc8213d to your computer and use it in GitHub Desktop.
sync forks via linking new remote to master branch

Sync forked repositories by creating remote to master branch

cd to Git

clone respository if necessary to local machine and then cd

git clone <repo-location>

The origin remote is pre-set for you by GitHub to point to your forked repo. Let's add another remote called upstream - this will be your main repo (the repo that you forked from). The command to do that is git remote add upstream <repo-location>


Making new branches

Our plan is to have our master branch of the forked repo mirror the master branch of the main repo while each feature we work on gets it's own branch. Let's say we wanted to add words to the words.txt file. In order to do that, let's create a branch called word-addition. This is done with the command git checkout -b <branch-name>. This creates a new branch and automatically switches you into it. git push origin word-addition

git commit -am "Description Here to commit new changes

git push origin word-addition to push to the newly created branch


Remember that upstream remote that we created? Well, it's time to bring it out to play. We first fetch the changes from upstream and then rebase our repo with upstream's master.

git fetch upstream check to make sure you are in master branch using git branch to check and git checkout <branch-name> to switch. git rebase upstream/master

check progress with git status

commit changes git push origin master


find new files as well as staging modified content and removing files that are no longer in the working tree

git add . -A
git commit -m "removed some files"
git push origin master


Quick re-cap

navigagte to local git repository
git fetch upstream
git checkout master
git merge upstream master
git push origin master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment