Hi All. In this post we will learn how to delete a Git branch locally and remotely. Git makes managing multiple branches very easy and deleting a branch is also no exception.
How to delete a branch locally ?
First step is to checkout to a branch that you are not deleting. Git will not allow you delete a branch you are currently using. Now the required branch can be deleted using below mentioned command
git branch -d <branch_name>
Example: git branch -d feature/login
where feature/login is the branch name.
-d deletes a local branch if its already been pushed and merged with the remote branch. If you want to forcefully delete a branch even if it hasn’t been pushed or merged yet, use -D command as mentioned below
git branch -D <branch_name>
How to delete a remote branch ?
Below is the command to delete the remote branch
git push <remote> --delete <branch_name>
Example: git push origin --delete feature/login
where feature/login is the branch name.
Happy Learning 🙂