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?
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.
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.
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.
As Uli Köhler already said:
git branch -D -- --track
The command will work to delete your branch.
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