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
Written by Daniel villa
Related protips
1 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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Branch
Authors

niklongstone
42.01K

muzzlefork
11.98K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#