In this article, we are going to learn about how to delete a git branch Locally and Remotely.
How to Delete a remote branch
To delete a branch on the origin remote repository, you can use Git version 1.5.0 and newer.
git push origin : <branchName>
you can delete a remote branch using
git push origin --delete <branchName>
To delete a local remote-tracking branch:
git branch --delete --remotes <remote>/<branch>
git branch -dr <remote>/<branch> # Shorter
git fetch <remote> --prune # Delete multiple obsolete tracking branches
git fetch <remote> -p # Shorter
To delete a branch locally. Note that this will not delete the branch if it has any unmerged changes:
git branch -d <branchName>
To delete a branch, even if it has unmerged changes:
git branch -D <branchName>
How to Delete a branch locally
$ git branch -d dev
Deletes the branch named dev if its changes are merged with another branch and will not be lost. If the dev branch
does contain changes that have not yet been merged that would be lost, git branch -d will fail:
$ git branch -d dev
error: The branch 'dev' is not fully merged.
If you are sure you want to delete it, run 'git branch -D dev'.
Per the warning message, you can force delete the branch (and lose any unmerged changes in that branch) by
using the -D flag:
$ git branch -D dev
0 Comments