Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a branch starting with a hyphen

Tags:

git

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

like image 643
UsAaR33 Avatar asked Apr 19 '11 03:04

UsAaR33


People also ask

How do I completely 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 I permanently delete a branch in GitHub?

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).

How do I delete a branch not on a remote?

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.

How do I delete a branch in Linux?

-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:

How do I list all the local branches I have?

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:

How to delete a remote branch in Git?

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.

When should I use the delete button on a local branch?

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.


2 Answers

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.

like image 200
Josh Lee Avatar answered Sep 22 '22 01:09

Josh Lee


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'
like image 21
Andy White Avatar answered Sep 22 '22 01:09

Andy White