Git: Create a Branch

Create a branch from master

This is quite staightforward, type the following.


git branch NewBranchName

The branch NewBranchName is now created from master, but you will not be changed to it right away. To start using it, you must checkout into the branch.


git checkout NewBranchName

Create a branch from another branch

Some times you might need to create a sub module in your development project. Creating a sub branch from you working branch is the perfect solution.


git checkout -b NewBranchName ExistingBranchName

Make sure you type the new branch name first then the existing branch.

Note: since you are using git checkout -b you will automatically be switch to this branch.

Use the new branch

At this point your new branch has now been created. To start using it, you need to change change to your new branch.


git checkout NewBranchName

Pushing your new branch to the git server (origin)

git push --set-upstream origin NewBranchName

Links

Advertisement