Git checkout a remote branch
One of the first Git commands you’ve learned ws certainly “git checkout”:
1
$ git checkout development
In this simplest form, it allows you to switch(and even create) local branches -something you need countless times in your day-to-day work.
However, git checkout’s power is not limited to local branches: it can also be used to create a new branch from a remote one.
Collaborating with Branches
Remember that branches are the main way of collaboration in Git. Let’s say that one of your colleagues wants you to collaborate on(or review) a piece of code:
She will push the corresponding branch to your common remote server.
In order to see this newly published branch, you will have to perform a simple “git fetch” for the remote.
Using the “git checkout” command, you can then create a local version of this branch - and start collaborating.
Checking out for remote branches
The syntax for making git checkout “remote-ready” is rather easy: simply add the “–track” flag.
1
$ git checkout --track origin/branch-a
Based on the remote branch “origin/branch-a”, we now have a local branch named “branch-a”.
Note that, by default, Git uses the same name for the local branch. Being a good convention, there’’s rarely the need to change this.