I\'m trying to learn how to use Git and have created a small project with an HTML, CSS, and Javascript file. I made a branch from my basically empty project and then made so
Deleting my commit message worked for me.
rm .git/COMMIT_EDITMSG
It then said.
fatal: cannot lock ref 'HEAD': Unable to create '.git/refs/heads/[your-branch-name].lock': File exists.
Do notice that your branch name might be different than mine. You can delete this lock file by doing;
rm .git/refs/heads/[your-branch-name].lock
Hope this helps someone.
In case can help somebody else...
I tried with command line rm -f .git/index.lock and didn't work (terminal didn't show any error). I just went directly to folder .git and delete the index.lock file.
Note: .git folder is located in your root repository and is hidden. In mac: Cmd+Shift+. to see hidden files.
rm -f .git/index.lock didn't help, because I had a locked file that couldn't be deleted. So, index.lock also had been captured by some application.
In Windows I downloaded an alternative to Unlocker called Lock Hunter and deleted both files. Git captured them.
Had the same problem using SourceTree. But there were no any index.lock file on my host at all. I've found packed-refs.lock file, and after deleting it, the problem was solved.
For me the problem was simpler, this was in source tree so I'm not sure how much it'll apply to regular solutions but I accidentally had my master branch selected trying to make a commit rather than my uncommitted changes.
This wouldn't normally be a problem but I had already preemptively entered a commit message so I could track what I was doing for that little sprint I was on.
Basically, I started a commit on the uncommitted branch and was accidentally trying to start another commit on my master branch.
Delete index.lock in here:
<path to your repo>/.git/index.lock
Also, if your repository has submodules, delete all index.lock in here as well:
<path to your repo>/.git/modules/<path to your submodule>/index.lock