Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git cannot delete local branch

Tags:

git

git-branch

I was trying to track a remote branch with $ git checkout -b --track global/master, and git created a branch named "--track". Now, when I run $ git branch -D --track it won't delete the branch. I believe Git is parsing the last argument, --track, as a git-branch subcommand flag, not a branch name.

I attempted to quote the branch name with $ git branch -D '--track' and escape the leading hyphen with $ git branch -D \--track.

How can I delete the "--track" branch?

like image 301
Shane Avatar asked Mar 01 '14 00:03

Shane


People also ask

Why can't I delete local branch?

In some cases, Git might refuse to delete your local branch: when it contains commits that haven't been merged into any other local branches or pushed to a remote repository. This is a very sensible rule that protects you from inadvertently losing commit data.

Can you delete local branches?

Deleting a branch LOCALLYDelete 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 delete a local branch if the remote branch is deleted?

First, use the git branch -a command to display all branches (both local and remote). Next, you can delete the local branch, using the git branch -d command, followed by the name of the branch you want to delete.


1 Answers

As Uli Köhler already said:

git branch -D -- --track

The command will work to delete your branch.

like image 91
Langusten Gustel Avatar answered Oct 07 '22 08:10

Langusten Gustel