I created a local empty branch with:
mkdir test
cd test
git checkout -b branch_local
I am not able to delete it with:
git branch -D branch_local
I get
error: Cannot delete branch 'branch_local' checked out at 'D:/test'
Please advise.
I created a local empty branch with:
mkdir test
cd test
git checkout -b branch_local
I am not able to delete it with:
git branch -D branch_local
I get
error: Cannot delete branch 'branch_local' checked out at 'D:/test'
Please advise.
Check out on different branch before deleting the branch to be deleted. For example :
STEP 1: git checkout master
STEP 2: git branch -D branch_local
branch_local is the name of branch to be deleted.
If you want to remove your repository and keep the files in it, you can remove the .git/ directory in test/. WARNING: This will destroy your history!
If you want to remove the repository and the files, you can remove the directory test/. WARNING: This will destroy the history AND the files!
If you want to destroy the new branch and switch to another one (this is what I think you want to do), you need to check out that branch first.
If it exists, you run git checkout <branch_name> && git branch -D branch_local. If the other branch doesn't exist, you add the -b flag: git checkout -b <branch_name> && git branch -D branch_local WARNING: The history in branch_local will be lost unless you keep the hash of the commit and prevent any garbage collections.
If you want to remove the branch without checking out a new one, you can remove the file .git/refs/heads/branch_local. Git will still think that you have this branch checked out since that name is in the .git/HEAD file, and this file is needed for the repository to be valid.
Note that if you created the new branch from an initial commit, the file .git/refs/heads/branch_local won't exist, and nor will the branch.
The name is only the name of the branch to be created if you make a commit, and this name is stored in the .git/HEAD file, which contains the line
ref: refs/heads/branch_local
Thus you can edit the file directly, or do it using the git commands above.
In summary, there has to be a name of a branch in the .git/HEAD file or the repository is invalid, regardless of whether the branch actually exists.
git status in the repository, you should get an error message now. I'd suggest you put that line back, but replace the branch name with another one.