On the second day of Commitmas, I had a new hurdle to jump — I forked @mjbrender’s repo, submitted a PR, and he accepted my changes as well as changes from @joshcoen and now my fork is outdated. How do I update my fork and local repo with the changes?
To rectify this, we’re going to leverage two git commands: git remote add upstream and git fetch upstream command.
With git remote add upstream, we’re going to specify the repository that we forked. In my case, I did:
git remote add upstream https://github.com/mjbrender/12-days-of-commitmas
A git remote -v verifies that we added the upstream source:
Then we perform git fetch upstream to copy the original repository (the one we forked) to our local repository (on our dev box):
Now we just fetched the upstream/master branch/repo and needs to be merged into our master branch. We can switch to our master branch with git checkout master.
Finally, git merge upstream/master to merge upstream/master to our master branch.
The final stretch! Our local repository is now a clone of the original repository again but we need to push our changes back to our repository on GItHub.
Done! Join in the Commitmas conversation on Twitter using the #vBrownBag hashtag! Happy committing!