Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force-delete a branch in Git? [duplicate]

Tags:

git

git-branch

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.

like image 863
Aditi Yadav Avatar asked Dec 29 '16 12:12

Aditi Yadav


People also ask

How do you force delete a branch?

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.

How do I force delete a remote branch?

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 .

How do you delete a git branch both locally and remotely?

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 .


1 Answers

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.

like image 63
Brijesh Avatar answered Oct 29 '22 13:10

Brijesh