Create a branch locally in Git

Reading Time: < 1 minutes

You can create a branch locally as long as you have a cloned version of the repo, but first, from your terminal window, list the branches on your repository. To do so, run the command below:

$ git branch 
 * master

This output indicates there is a single branch, the master and the asterisk indicates it is currently active.

Create a new feature branch in the repository.

$ git branch <feature_branch>

Switch to the feature branch to work on it.

$ git checkout <feature_branch>

You can list the branches again with the git branch command.

Commit the change to the feature branch:

$ git add . 
$ git commit -m "adding a change from the feature branch"

Switch back to the master branch.

$ git checkout master

Push the feature branch to repository.

git push origin <feature_branch>

Great Job.


Was this post helpful?

Leave a Reply