Jeremy Minton About
Creating Git Branches Remotely and Locally
Posted by Jeremy Minton, , 0 comments.

Creating a Branch Locally

This will create a new local branch called ‘localbranchname’ which will be a copy of the currently checkedout branch.

git checkout -b <localbranchname>

This is the equivalent to

git branch <branchname>
git checkout <branchname>

where the first command creates the branch (a new pointer to the current commit) and the second command checkouts the newly created branch.

Pushing a new Branch to the Remote Repo

Once a branch has been created locally, and additional commits made perhaps, it is often necessary to push this to the remote repository for safe keeping or distribution. This is achieved with

git push -u origin <branchname>

Note: this cwas introduced in Git 1.7.0 so only works on this version or later. Previous versions require setting up tracking information.

Pulling a new Branch from a Remote Branch

If a branch was created on another workstation then pushed to the remote repository it can be pulled using

git fetch 
git checkout <remotebranchname>