[GitHub] How to Sync a Forked Repository with the Original Repository
I’ll introduce the procedure for syncing a forked repository on GitHub to follow the original repository.
Prerequisites
We assume you’ve already forked some repository on GitHub.
Git clone the forked repository
First, git clone the forked repository.
git clone git@github.com:your_account/sample_repository.git
Set the original forked repository as a remote repository named upstream
Set the original repository you forked from as a remote repository with the name “upstream”.
git remote add upstream git://github.com/original_account/sample_repository.git
From now on, you can handle the original forked repository with the name “upstream”.
You only need to set this up once initially; no reconfiguration is needed.
Confirm the upstream repository with git branch -a
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/upstream/master
Git fetch and merge to follow changes in the original repository
First, git fetch upstream
$ git fetch upstream
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 1 (delta 0)
Unpacking objects: 100% (1/1), done.
From git://github.com/original_account/sample_repository
* [new branch] develop -> upstream/develop
* [new branch] master -> upstream/master
Then git merge
Merge the differences obtained with git fetch into the current branch.
$ git merge upstream/master
Updating 1e579f8..21e70ae
Fast-forward
For those unfamiliar with OSS development, working with forked repositories on GitHub and syncing with the original branch is probably uncommon, so I hope this article helps even a little.
Reference Information
That’s all from the Gemba.