git: switch branch without detaching head

# first time: make origin/branchname locally available as localname
git checkout -b localname origin/branchname 

# othertimes 
git checkout localname 

git push origin

For convenience, you may use the same string for localname & branchname
When you checked out origin/branchname you weren’t really checking out a branch.
origin/branchname is a “remote” name, and you can get a list of them with

branch -a 

If you have colours enabled, local branches will be one colour, and remote another.

You have to first make a remote branch tracked locally in order to be able to switch-to and work on it.

Leave a Comment