Get a remote branch into your freshly cloned local repository

If you have just cloned a repos­i­tory, by default git places you on the mas­ter branch. Even if you do a ‘git branch’ it just shows you the mas­ter branch because that is all you have locally. How­ever, if you want to work on another remote branch instead of the mas­ter, you will first need to do a check­out that remote branch. You heard that right, you gotta check­out a branch that is not even listed on your local repository.

To know what branch you need to check­out from your remote, run the command

git branch -a

Lets say your ori­gin had a branch called bug-01. Then, to check­out that branch, run

git branch --track bug-01 origin/bug-01

Of course, you can also spec­ify a com­pletely dif­fer­ent branch name dur­ing check­out. e.g.

git branch --track bug-01-is-a-feature origin/bug-01

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *