sync fork with remote git

Software developers or open source software (OSS) contributors that use GitHub to manage their projects probably use one of two git workflows :

  1. fork master branch, i.e main repository, to create a personal copy of the project --> clone fork to local workstation --> create a new local branch from fork --> make relevant changes on local branch --> commit changes to local branch --> push local branch to origin, i.e your forked copy on GitHub --> submit a pull request (PR),
  2. clone master branch, i.e main repository to create a personal copy of the project --> create a new local branch from master --> make relevant changes on local branch --> commit changes to local branch --> push branch to origin --> submit a PR.
Which of these two workflows the developers follow depends on many things. And now that I've introduced you to the basic workflow and the premise as to why/how I ran into a problem, I can tell you about the problem and the solution for it.

If you follow the first of the two workflows, I expect you to run into this problem. Say you submit a PR, which has been accepted and merged into the master branch of the project. Now, because you forked the master branch, to create a personal copy, before this PR was merged, your fork/copy is behind the original master.

So, to sync your forked master with the original master, you will have to do two things :
  1. Set upstream so that git knows where this repository/project was forked from.
  2. Fetch upstream and merge upstream/master with your master.
You can refer to the following two help articles on Github. The relevant commands are :


1
2
3
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
git fetch upstream
git merge upstream/master

You can run the following git command to double check what all remotes has been set


1
git remote -v

and you should run the following git command to switch to the local master branch before you merge upstream/master.


1
git checkout master

Popular posts from this blog

Animation using GNUPlot

Arxiv author affiliations using Python

Thoughts on the National Deep Tech Startup Policy