29

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://git@bitbucket.org/majuri/breakit-web-app.git
 ! [remote rejected] master -> master (failed to lock)
error: failed to push some refs to 'ssh://git@bitbucket.org/majuri/breakit-web-app.git'

Here is a screenshot: enter image description here

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. enter image description here

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

Grigory Zhadko
  • 1,484
  • 1
  • 19
  • 33
mu_sa
  • 2,685
  • 10
  • 39
  • 58
  • What is the output from `git show-ref refs/remotes/origin/master`? – vergenzt Jun 27 '12 at 15:08
  • $ git show-ref refs/remotes/origin/master 6a47a0fd398610a75bdab8976f842dc0efd89f86 refs/remotes/origin/master – mu_sa Jun 27 '12 at 15:51
  • What does `git fetch origin` output? Maybe your remote tracking branches got out-of-sync or something...? – vergenzt Jun 27 '12 at 15:57
  • It outputs nothing... Salman@PC_HOME ~/git/breakit-web-app (master) $ git fetch origin – mu_sa Jun 27 '12 at 16:00
  • What is the output of `git rev-parse --symbolic-full-name master`, `git rev-parse master`, and `git show-ref master`? – Richard Hansen Jun 27 '12 at 17:43
  • Salman@PC_HOME ~/git/breakit-web-app (dev270612) $ git rev-parse --symbolic-full-name master refs/heads/master – mu_sa Jun 27 '12 at 19:40
  • Salman@PC_HOME ~/git/breakit-web-app (dev270612) $ git rev-parse master 0da090c5cbde10ff19602a2722ae05231c30dff5 – mu_sa Jun 27 '12 at 19:41
  • Salman@PC_HOME ~/git/breakit-web-app (dev270612) $ git show-ref master 0da090c5cbde10ff19602a2722ae05231c30dff5 refs/heads/master 6a47a0fd398610a75bdab8976f842dc0efd89f86 refs/remotes/origin/master – mu_sa Jun 27 '12 at 19:41
  • what about `git cat-file -t 6a47a0fd3`, `git branch -a --contains 6a47a0fd3`, and `git ls-remote origin master`? (Please edit the question and put the information there rather than in comments.) – Richard Hansen Jun 27 '12 at 23:49
  • I have forced push to my old version in the master from where the tracking branch was going out of sync. – mu_sa Jun 28 '12 at 06:10

3 Answers3

34

You have to update the HEAD known by git. It will be transparent for you.

  1. Go to master branch

    git checkout master
    
  2. Get updates from the remote to your local repository

    git fetch
    
  3. Update your local repository using rebase instead of merge. See there difference between git pull and git rebase

    git rebase origin/master
    
  4. Push your master branch

    git push origin master:master
    
Seki
  • 11,135
  • 7
  • 46
  • 70
Flows
  • 3,675
  • 3
  • 28
  • 52
4

If you tried all these above steps and did not work, try the following command.

rm -fr ".git/rebase-merge"
Ali Turki
  • 1,265
  • 2
  • 16
  • 21
2

git pull origin master --rebase

this worked for me

Adithya
  • 59
  • 2