- Published on
Sync your Git Fork to the Original Repo
- Authors
List the currently configured remote repositories
git remote -v
Result Befor set upstream:
origin https://github.com/[Your UserName]/[Your Fork].git (fetch)
origin https://github.com/[Your UserName]/[Your Fork].git (push)
Add the original repository as an upstream repository
git remote add upstream https://github.com/[Original Owner Username]/[Original Repository].git
Now try again
git remote -v
Result After set upstream:
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 Username]/[Original Repository].git (fetch)
upstream https://github.com/[Original Owner Username]/[Original Repository].git (push)
Force your forked repo to be the same as upstream
The First Step (fetch)
git fetch upstream
The Main Step (reset and push)
Suppose we have a branch on our fork with name fork_branch and a branch on upstream with name upstream_branch. We want to sync fork_branch with upstream_branch
git checkout fork_branch
git reset --hard upstream/upstream_branch
git push origin fork_branch --force
Example
We want our develop brach of our fork same as develop branch of upstream.
git checkout develop (this develop is for fork. local)
git reset --hard upstream/develop (this develop is for upstream. remote)
git push origin develop --force (this develop is for fork. remote)