Git & GitHub Tips

Add Upstream Remote to Our Forked Git Repos

Assuming we have forked the repo.

Now we clone our forked repo:

$ git clone git@github.com:YOUR-USERNAME/THE-REPO.git

See what remotes we have:

$ git remote -vv
origin	git@github.com:YOUR-USERNAME/THE-REPO.git (fetch)
origin	git@github.com:YOUR-USERNAME/THE-REPO.git (push)

To add the upstream remote:

$ git remote add upstream git://github.com/UPSTREAM-USERNAME/THE-REPO.git
$ git remote -vv
origin	git@github.com:YOUR-USERNAME/THE-REPO.git (fetch)
origin	git@github.com:YOUR-USERNAME/THE-REPO.git (push)
upstream	git@github.com:UPSTREAM-USERNAME/THE-REPO.git (fetch)
upstream	git@github.com:UPSTREAM-USERNAME/THE-REPO.git (push)

Syncing a fork

  1. Fetch the branches and their respective commits from the upstream repository.

Commits to master will be stored in a local branch, upstream/master.

  1. Check out your fork's local master branch.

  1. Merge the changes from upstream/master into your local master branch.

This brings your fork's master branch into sync with the upstream repository, without losing your local changes.

If you just want to sync up without local changes, you may push it after git merge:

Check What's Going to be Pushed?

For a list of files to be pushed, run:

How to Delete Local and/or Remote Branch?

To Contribute Multiple PRs?

Better use a dedicated branch for one PR, like below.

For PR-1:

Now there is another PR-2 you want to do, while waiting for the PR-1 to be accepted and merged:

How to "Rollback" the versions of one specific file?

git push --set-upstream origin master but somehow the old user is being used?

If you checked through git config --global -l or cat ~/.gitconfig but same issue remains, it's most likely caused by OSX Keychain. Resolve it by following below steps:

  1. In Finder, search for the Keychain Access app

  2. In Keychain Access, search for github.com

  3. GitHub Password Entry in KeychainFind the "internet password" entry for github.com

  4. Edit or delete the entry accordingly.

Merge PR With Conflicts

Ref

Last updated

Was this helpful?