2

I have a problem with a git repo that is shared between multiple developers. A branch seems to have gone missing (kind of) and when I try to push to the remote repo with this branch I receive the following message...

To git@hades:bbis.git
 * [new branch]      dompdf0.52 -> dompdf0.52
 ! [rejected]        live -> live (non-fast-forward)
error: failed to push some refs to 'git@hades:bbis.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

There are 3 branches on the repo:

  • dompdf0.52 is a temp branch where I upgraded the dompdf (this is okay)
  • master
  • live (this is the problematic branch)

I am the only developer who uses the live branch (used for deploying to the live server), and I did some work directly in this branch (not a good idea I know, but this was a mistake) and committed locally. I get this error when I try to push.

Other developers have no visibility of the live branch or dompdf0.5.2 branch (I created both of these, but have pushed them to the remote repo - they even show up in the gitweb interface as HEADS). Even when developers do a git pull --all it still doesn't pull these branches down.

Another strange phenomenon is that when viewing the log on gitweb it only shows the master, but when looking at the shortlogs for live branch it shows live at the same point where the master is in the master shortlog.

I'm just a little confused as to what is going on here, from what I can see the live branch is in the remote repo but not showing in the main repo log.

Has anyone got any ideas? Let me know if you need any images from gitk

EDIT: Just thought I'd mention, I've tried to work around the error message by doing a git fetch and a git pull but to no avail. The only thing I've not tried is a git push --force because I don't want to lose my history.

EDIT 2: After running the script that sehe provided I received the following:

fatal: ref ed2cacdacad22c75ca765cfc996304c8c7c8a654 is not a symbolic ref
fatal: ref 98c37bd8a9ef2fc16e882c17b4c04f417ae7b2b2 is not a symbolic ref
JamesHalsall
  • 13,224
  • 4
  • 41
  • 66

2 Answers2

2

What you are experiencing is simply that you are not allowed to push because someone has updated the branch inbetween. You need to pull this branch before you can push your changes. The reason git pull --all doesn't work is probably because your local live branch is not setup to track origin/live

Try this:

git branch --set-upstream live origin/live
git checkout live
git pull
git push
rtn
  • 127,556
  • 20
  • 111
  • 121
1

Perhaps 'live' is a symbolic reference to master? In that case, it acts merely as an alias, and updating it would (potentially?) update the master reference.

Symbolic refs should be updated with git-update-ref. To be honest, I have only once used a symbolic reference and never pushed them to a remote. It is possible that git push (send-pack or receive-pack) doesn't understand symbolic refs and tries to treat them as a normal ref by first resolving the symbolic reference.

See What's the recommended usage of a Git symbolic reference? for background

Backgrounder of git refs: http://progit.org/book/ch9-3.html

Use this to find out whether your branches are symbolic refs:

for ref in $(git rev-list --branches --no-walk); do
    git symbolic-ref "$ref"
    git check-ref-format --print "$ref"
done

For all (remote) branches, add --all to rev-list

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thanks for the response, I will try this now. If I do `git branch live` to create the branch initially, would that have created a symbolic ref? – JamesHalsall Jun 16 '11 at 10:46
  • @sehe Can I execute `git` from within a script? Running that code from within a script throws an error about `git` not being a command – JamesHalsall Jun 16 '11 at 10:51
  • (1) symbolic-refs don't happen by accident (branching creates normal refs); (2) No doubt you are experiencing a PATH or alias problem; try using the full path (`/usr/bin/git` or `"c:\msysgit\msysgit\bin\git.exe"`) – sehe Jun 16 '11 at 10:57
  • @sehe thanks, I was doing something silly... I've added the output from that script (I get a fatal git error) – JamesHalsall Jun 16 '11 at 13:02
  • @Jaitsu: no you don't. You get an informational message confirming that the refs are _not_, in fact, symbolic. Which is what you wanted to verify. You can disregard my answer from now on :) – sehe Jun 16 '11 at 13:06