How to checkout to a remote branch that someone else is working on in git?

Ever been in a situation where you need to collaborate with someone, but you don't have that branch on our local repo? How do we get that, as doing a checkout will not work?

First, fetch all branches from remote:

git fetch --all

Say you want to checkout to production from the remote.

git checkout --track origin/production
# Branch production set up to track remote branch production from origin.
# Switched to a new branch 'production'
(--track is shorthand for git checkout -b [branch] [remotename]/[branch])

This will give you a local copy of the branch production, and any update that has been pushed will also show up remotely

Originally Posted On: Github (k88hudson)

Subscribe to GIT.WTF!?!

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe