Git Error: error: cannot lock ref "refs/heads/***/***": "refs/heads/***" exists; cannot create "refs/heads/***/***"

Git Error: error: cannot lock ref/heads

  Shubham Verma      June 28, 2021


Git Error: error: cannot lock ref "refs/heads/***/***": "refs/heads/***" exists; cannot create "refs/heads/***/***"

I was facing this error - cannot lock ref "refs/heads/***/***", while doing git push command. In this article, we will see how we can get the best solution of this error. This is in general issue if you are working with git.
I was doing code and wanted to commit and push my codes, I tried to push my codes but I was getting this amezing error. This error can also come at the time of doing git push. I explored a lot then got to know the solution and wanted to share this solution here. This is the very common error if you working with the git.

Why this error cannot lock ref "refs/heads/***/***"?

This error occures because it might possible that there is a branch with the same name already exist, or there is a branch is already created with the same name pattern.

For example, if you created a branch with ABC-1001 and later you want to create a branch with name ABC-1001/xyz, then this will throw the below error:

Git Error: error: cannot lock ref "refs/heads/ABC-1001/xyz": "refs/heads/ABC-1001 exists; cannot create "refs/heads/ABC-1001/xyz"

What is the solution of this error - cannot lock ref "refs/heads/***/***" ?

if you get the error: cannot lock ref "refs/heads/ABC-1001/xyz": "refs/heads/ABC-1001 exists; cannot create "refs/heads/ABC-1001/xyz", then you need to do the following things: 1. Delete the remote branch ABC-1001 2. Delete the local branch ABC-1001

1. Delete the remote branch ABC-1001

We need to delete the remote branch unsing following git command:

Before doing this, you need to check the remote name like wether this would be origin or upstream or anything else that you added before. To check this, run following command:
And see the which remote location we need to delete the branch.

Git Error: error: cannot lock ref refs/heads/***/***: refs/heads/*** exists; cannot create refs/heads/***/***

Git Error: error: cannot lock ref refs/heads/***/***: refs/heads/*** exists; cannot create refs/heads/***/***


Here I need to work on upstream, so my command would be -


Now the above command will delete the branch on your remote location.

You can also use this shorter command to delete a branch remotely:

Ex:


2. Delete the local branch ABC-1001

First of all, you need to checkout another branch which you are not going to delete, because git will not allow you to delete the branch you are currently on so you must make sure to checkout a branch that you are NOT deleting.

For example:
git checkout master Now we need to delete the local branch using following command:

For example:

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.

Now the local branch will be deleted successfully.

Now you have deleted the local and remote branches and you can create the branch and do the operation accordingly.


Support our IDKBlogs team


Welcome to IDKBlogs.

If our contents help you and you learned from this platform, please consider supporting what we do.

Thank you.




Strongly Recommended Books For You:

Reading books opens the door to allow in more lights, If we want to know a man of rare intellect, try to know what books he/she reads.

For India:

For Other Countries (United States, United Kingdom, Spain, Italy, Germany, France, Canada, etc)


Thank you

I appreciate you taking the time to read this article. The more that you read, the more things you will know. The more that you learn, the more places you'll go. If you’re interested in Node.js or JavaScript this link will help you a lot.

If you found this article is helpful, then please share this article's link to your friends to whom this is required, you can share this to your technical social media groups also. You can follow us on our social media page for more updates and latest article updates.
To read more about the technologies, Please subscribe us, You'll get the monthly newsletter having all the published article of the last month.



Funny Programming | Idkblogs.com | Shubham Verma

👈

Enjoyed this moment?