Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git branch -d <branchname> throws error: branch <branchname> not found

Tags:

When I type git branch, I get

* master localbranch 

But when I try to remove the branch, git branch -d localbranch, I get a not found error:

error: branch 'localbranch' not found. 

I have also tried to force the delete with git branch -D localbranch, but it is giving me the same error.

The branch was corrupted and I did the following procedure, Git repository corrupt (incorrect header check; loose object is corrupt), to remove the corrupted files. But now I cannot delete the branch.

like image 526
Johnny Dew Avatar asked Feb 11 '15 18:02

Johnny Dew


People also ask

What is git branch Branchname?

A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master . As you start making commits, you're given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically.

When moving to a branch to create the branch it if it does not exist?

The command checkout -b creates a new branch and then checks out to that branch. So, if a branch already exists, it cannot create a new one. The above command does in a context sensitive way. If there's a branch, it switches, if not, it creates and checkout.

What is git checkout Branchname?

You can not only create a new branch but also switch it simultaneously by a single command. The git checkout -b option is a convenience flag that performs run git branch <new-branch>operation before running git checkout <new-branch>. Syntax: $ git checkout -b <branchname>

How do you fix this branch is out of date with the base branch?

Update your pull request branch by rebasing When your pull request's branch is out of date with the base branch, you now have the option to update it by rebasing on the latest version of the base branch.


1 Answers

Branches are stored as files containing the SHA they point to. Try deleting the file for this branch, named localbranch, from the .git/refs/head/ directory within your project:

rm .git/refs/heads/localbranch 
like image 64
Anshul Goyal Avatar answered Oct 06 '22 03:10

Anshul Goyal