Skip to content

Instantly share code, notes, and snippets.

@samyarmodabber
Last active March 14, 2024 07:20
Show Gist options
  • Save samyarmodabber/1d9bb435eeda2065dbcab56f7e1d2339 to your computer and use it in GitHub Desktop.
Save samyarmodabber/1d9bb435eeda2065dbcab56f7e1d2339 to your computer and use it in GitHub Desktop.
What you need know about Fork

1_IelAxduwS_YtpsrlRe1d0Q

Sync your Git Fork to the Original Repo

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment