I managed to create a branch in git called '-f'
e.g.
$ git branch
* (no branch)
-f
How do I delete the dang thing? git branch -d -f won't work, nor will git branch -d '-f' or even git branch -d -f -f
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 .
On GitHub.com, navigate to the main page of the repository. Above the list of files, click Branches. Scroll to the branch that you want to delete, then click . If you try to delete a branch that is associated with at least one open pull request, you must confirm that you intend to close the pull request(s).
Remove All Local Branches not on Remote First we get all remote branches using the git branch -r command. Next, we get the local branches not on the remote using the egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) command, Finally we delete the branches using the xargs git branch -d command.
-d is a flag, an option to the command, and it's an alias for --delete. It denotes that you want to delete something, as the name suggests. - local_branch_name is the name of the branch you want to delete. Let's look into this in a bit more detail with an example. To list out all the local branches, you use the following command:
To list out all the local branches, you use the following command: I have two, branches, master and test2. I am currently on the test2 branch as the (*) shows: I want to delete the test2 branch, butit is not possible to delete a branch you are currently in and viewing. If you try to do so, you'll get an error that will look something like this:
The command to delete a remote branch is: Instead of using the git branch command that you use for local branches, you can delete a remote branche with the git push command. Then you specify the name of the remote, which in most cases is origin.
Use it only when you are absolutely sure you want to delete a local branch. If you didn't merge it into another local branch or push it to a remote branch in the codebase, you will risk losing any changes you've made. Remote branches are separate from local branches.
git branch -d -- -f
The --
symbol in general will stop parsing of command line options with many Linux tools.
Another way is
git update-ref -d refs/heads/-f
but git-update-ref
is rather dangerous.
Not sure if this will work, but a --
argument in Unix/Linux-style commands often tells the command that you're done passing options, and now you're passing real arguments:
git branch -d -- '-f'
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