Last Updated: February 25, 2016
·
9.607K
· dvilla

Create a new branch and track a remote branch

//to see available branches and remotes

git branch -a

//to create a new branch and track and existing branch

git checkout -b nameofmybranch --track remotebranch

i.e.

git checkout -b store --track origin/store

//you can name your branch whatever
//you like but I recommend you to call
//it as your remote branch to avoid confusions

1 Response
Add your response

I use a gem called grb (https://rubygems.org/gems/grb) to do most of my branch maintenance. It adds 2 steps to the process of creating and tracking a new branch: pushing a ref head and then fetching the branch you're branching off of. It's a more complete algorithm, I think. It also has commands for adding remotes, deleting branches (locally and remotely), renaming branches, etc.

! grb new foo --explain
git push origin my_current_branch:refs/heads/foo
git fetch origin
git branch --track foo origin/foo
git checkout foo
over 1 year ago ·