The command to create, delete or list branches.
Note: A newly created branch won’t be switched to automatically.
By only providing a name,
git branch will use your current branch as the starting point when creating a new branch.
$ git branch <name>
If you want the new branch to use an existing branch or tag as its starting point you can pass it in as a second argument.
$ git branch <name> <branch|tag>
You’re currently on the
bugfix branch, however you want to create a new
feature branch using
master as the starting point.
Rather than running the following:
$ git checkout master $ git branch feature
You can simply run the following instead:
$ git branch feature master
Note: Using these commands will only delete the branch in your local copy of the repository. Learn how to delete a remote Git branch.
The branch will only be deleted if either:
- The branch has been fully merged with its corresponding remote branch.
- In HEAD if no remote branch has been set.
$ git branch -d <branch>
$ git branch -D <branch>