DEV Community

Louise Fitzpatrick Hayes
Louise Fitzpatrick Hayes

Posted on

Git add an upstream to a forked repo

Thanks for taking the time to check this out! Please feel free to add helpful comments or feedback!

This is a mini cheat sheet that assumes you are familiar with git, and have all tools installed, and a project terminal session open in your editor.

This assumes you have forked a repo using the GIT gui.

git clone -v <git url>

To rebase your branch with the upstream branch (remote branch from which you forked your branch),

you need add the branch to your list of 'remote branches' as an upstream, adding it to the list of remote branches visable via the git branch -av command.

git checkout <your-origin-branchname> (e.g. git checkout master)

Switched to branch 'your-origin-branch'
Your branch is up-to-date with 'origin/your-origin-branch'.

git remote add upstream <remote branch url> 

e.g. git remote add upstream https://github.com/cypress-io/cypress.git

Adds the remote branch to your repo as upstream. To check this:

git remote -v

You should see:

git remote -v
origin  https://github.com/louise-hayes/Project-3-Speech.git (fetch)
origin  https://github.com/louise-hayes/Project-3-Speech.git (push)
upstream        https://github.com/peraltot/Project-3-Speech.git (fetch)
upstream        https://github.com/peraltot/Project-3-Speech.git (push)

Next, from within the your correct branch...

git pull upstream <your-origin-branch>

This Updates your branch from upstream

check all branch #'s to ensure all on same git#!

git branch -av

You will see:

  1. your master (6266a2b) matches remote/upstream/master(6266a2b).
  2. your /remote/origin/master (6266a2b) matches remote/upstream/master(6266a2b). These 3 repos (local master, upstream master and origin master) need to match.
git branch -av
* master                          6266a2b Update README.md
  remotes/origin/HEAD             -> origin/master
  remotes/origin/master           6266a2b Update README.md
  remotes/origin/textfile-working ead5671 added body-parser, jquery for  calls to fix /saved POST
  remotes/upstream/master         6266a2b Update README.md


Hope this helps!

Top comments (0)