HOW TO: Setup a new local & remote Git Branch

A question came up in the office today:

What’s the best way to create a new tracking branch both locally and on the server?

Steve decided this 2-liner was best:

git checkout -b newBranch
git push -u origin newBranch

Have a better way? Let us know!

Photo of Daniel Morrison

Daniel founded Collective Idea in 2005 to put a name to his growing and already full-time freelance work. He works hard writing code, teaching, and mentoring.


  1. January 28, 2011 at 21:12 PM

    I love the git_remote_branch gem.

    grb create and you are done.

    January 31, 2011 at 10:02 AM

    If you set branch.autosetupmerge = true you can avoid the -u I think. But you still need the two commands.

    Deleting a remote branch is kinda clunky using pure git. grb makes sense there (even though I don’t use it).