While I was playing around with the Git flow, I received the following error: error: Cannot delete branch <some-branch> checked out at <some-location>
as I was trying to remove a local branch that I was working on. Obviously you can’t remove a branch where HEAD
is currently pointing at. And for the solution, pretty straightforward.
Prerequisites
- Git
Solution
Step 1. Check out another branch. For instance:
git checkout main
Step 2. Pull any changes.
git pull
Step 3. Remove the local branch causing the error.
git branch -D feature1
Step 4. Optionally, delete the remote branch as well.
git push origin -d feature1
Conclusion
To find more neat Git commands and hacks, simply browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.