Git Branch is today’s tutorial. Branches can be created, renamed, listed and deleted using git branch command. Keep in mind that all git branches are simply indicators to commits in a specific repository. So let’s get started.
Post Contents
# Requirements
- Git installed in your system. Download
# Get Branch
You can get all local branches with following command.
git branch
Also, you can get all remote branches along with all local branches using -a option.
git branch -a
You can get a list of branches that are not merged with a current branch with --no-merged flag.
git branch --no-merged
Similarly, you can get a list of branches that are merged with a current branch with --merged flag.
git branch --merged
# Create Branch
You can easily create a branch using the following command.
git branch <branch-name>
Remember, pushing into remote with git push origin will automatically create a remote branch.
# Delete Branch
Execute the following command to remove a local branch.
git branch -d <branch-name>
Likewise, to force delete a branch use -D option.
git branch -D <branch-name>
Remote branch can be removed with using following command.
git push origin --delete <branch-name>
# Rename Branch
You can rename a local branch with the usage of following command.
git branch -m <branch-name>
Above command will rename the current branch. But if you want to rename another branch then use.
git branch -m <old-branch-name> <new-branch-name>