This is here more as a future note to myself, but hopefully someone out there will find this useful.
Essentially, imagine this: You have a remote repository (say, on GitHub), and that repo has many branches. You clone the repo and end up with the master branch in your local dev environment. Now what happens if you want to use one of the other branches in the repo?
Well, initially, you’d think you would create the branch locally, and pull the differences down:
git branch production git checkout production git pull origin production
but what if master is ahead of production (a likely scenario)? In this case this won’t work as your local production branch will now contain the changes in the master branch – as that’s where you originated production from on your machine.
What you need to do is:
git checkout -b <local_name_for_branch> <remote_source>/<remote_branch>
e.g
git checkout -b production origin/production
What this does is create a tracking branch. Tracking branches are local branches that have a direct relationship to a remote branch. If you’re on a tracking branch and type git push, Git automatically knows which server and branch to push to. Also, running git pull while on one of these branches fetches all the remote references and then automatically merges in the corresponding remote branch.











