I am relatively new to git and am facing this problem. The git push command shows the error below. I will explain to you from the beginning what I had been trying to do. I created a submodule, committed, and pushed it. The push throws the error below.
Salman@PC_HOME ~/git/breakit-web-app (master) $ git push origin master error: refs/heads/master does not point to a valid object! Counting objects: 4, done. Delta compression using up to 2 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 421 bytes, done. Total 3 (delta 1), reused 0 (delta 0) remote: bb/acl: salmanmanekia is allowed. accepted payload. error: Ref refs/heads/master is at 6a47a0fd398610a75bdab8976f842dc0efd89f86 but expected 00000000000000000000000000000000000000000 remote: error: failed to lock refs/heads/master To ssh://[email protected]/majuri/breakit-web-app.git ! [remote rejected] master -> master (failed to lock) error: failed to push some refs to 'ssh://[email protected]/majuri/breakit-web-app.git'
Here is a screenshot:
After that, I tried some solutions, but none of them worked. I will also explain briefly what I have been trying.
1: From the bitbucket repo, I noticed there are some dangling commits (the red arrow in picture 2), so I gave the following commands to solve that git gc and git prune.
2: I also tried commands like git revert HEAD and git push origin HEAD --force, but none seem to work.
Other details:
$ git rev-parse --symbolic-full-name master refs/heads/master $ git rev-parse master 0da090c5cbde10ff19602a2722ae05231c30dff5 $ git show-ref master 0da090c5cbde10ff19602a2722ae05231c30dff5 refs/heads/master 6a47a0fd398610a75bdab8976f842dc0efd89f86 refs/remotes/origin/master
Thank you
Quick fix : Remove and re-add remote The quickest way you can get rid of "error: cannot lock ref" is to remove the remote so that you can add it again later.
Update local repository Execute the following command. It removes all branches from the local repository that have gone from the remote repository. Try to execute git pull or git fetch . It should work now.
You have to update the HEAD known by git. It will be transparent for you.
Go to master
branch
git checkout master
Get updates from the remote to your local repository
git fetch
Update your local repository using rebase instead of merge. See there difference between git pull
and git rebase
git rebase origin/master
Push your master
branch
git push origin master:master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With