I have created a branch test
in my Git repository. Now I have no use for it. How can I force-delete this branch?
I tried the following command:
git branch -d test
But it returns an error.
Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet.
Deleting remote branches To delete a remote branch, you can't use the git branch command. Instead, use the git push command with --delete flag, followed by the name of the branch you want to delete. You also need to specify the remote name ( origin in this case) after git push .
So, to delete the remote branch AND locally-stored remote-tracking branch in one command, just use git push origin --delete <branch> . Then, you just need to delete the local branch with git branch -D branch .
You can force-delete a branch with the following command:
git branch -D test
By replacing -d
with -D
, you are telling git to delete the branch and that you don't care to merge changes from that branch.
Be careful, you can lose data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With