Pull a new branch from to GitHub to a second computer (if it doesn’t exist there yet)

Say you’ve started working on a new feature on computer A, then pushed that branch (new-feature) up to GitHub, and now want to continue working on that feature on computer B, but haven’t yet established that branch locally on computer B.

Here’s what to do:

1) This establish the branch locally:

git fetch origin new-feature:new-feature

2) This checks out the branch locally

git checkout new-feature

3) Now that you’re on the new-feature branch locally, you need to set it so that when run git pull and git push while on this branch, it pulls/pushes that branch to/from github to/from your local version of that branch.

git branch --set-upstream-to=origin/new-feature new-feature

4) Now you can do git pull to pull the latest code down from this branch on github to this branch on local computer B.

git pull

Last updated