After forking one repository, if this repository updated, we need to keep up-to-date with this upstream repository.
Configuring a remote for a fork
Check current configured remote repository for your fork.
Using git remove -v
to check remote repository status.1
2
3git remote -v
> origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
Create a new remote upstream repository
1 | git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git |
Verify
Verify the new upstream
repository you’ve specified for your fork.1
2
3
4
5git remote -v
> origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
> origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
> upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
> upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
Syncing a fork
Fetch
Fetch the branches and their respective commits from the upstream repository. Commits to master
will be stored in a local branch, upstream/master
.1
2
3
4
5
6
7git fetch upstream
> remote: Counting objects: 75, done.
> remote: Compressing objects: 100% (53/53), done.
> remote: Total 62 (delta 27), reused 44 (delta 9)
> Unpacking objects: 100% (62/62), done.
> From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY
> * [new branch] master -> upstream/master
Switch to local master
1 | git checkout master |
Rebase the changes from upstream/master into your local master
1 | git rebase -i upstream/master |
If no conflict, move to next step.
If any conflict, figure out conflict part, then add changes.1
git add CONFLICT_FILE
Continue to rebase1
git rebase --continue
Push to origin master
Push your up-to-date local repo to origin master1
git push origin master