Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to resolve reference refs /refs/remotes/origin/branch while pushing after merging branches

New to git and github.

I want to replace the git master branch with my other branch bridge both locally and remotely. The problem is that git is unable to resolve the references for the bridge branch. The problem arises from pushing to github.

How the git tree came to be this way:

  1. Started master branch via the Git GUI.
  2. Continued and then realized it wasn't that great and transitioned to the Bash.
  3. Wasn't able to push to github anymore to master as the tip of the local master branch was one behind the tip of the remote counterpart.
  4. To circumvent, I created another branch called bridge. I didn't like that I had made bridge the default so I then tried to change it back to master using:

    git checkout better_branch
    git merge --strategy=ours master    # keep the content of this branch, but record a merge
    git checkout master
    git merge better_branch             # fast-forward master up to the merge
    
  5. It worked locally. However, when I tried to push I got the following:

    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master)
    $ git push
    warning: push.default is unset; its implicit value is changing in
    Git 2.0 from 'matching' to 'simple'. To squelch this message
    and maintain the current behavior after the default changes, use:
    
      git config --global push.default matching
    
    To squelch this message and adopt the new behavior now, use:
    
      git config --global push.default simple
    
    See 'git help config' and search for 'push.default' for further information.
    (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
    'current' instead of 'simple' if you sometimes use older versions of Git)
    Enter passphrase for key '/c/Users/NAME/.ssh/id_rsa':
    To [email protected]:NAMEtaylor/tabtrack.git
     ! [rejected]        master -> master (non-fast-forward)
    error: unable to resolve reference refs/remotes/origin/bridge: No error
    error: Cannot lock the ref 'refs/remotes/origin/bridge'.
    error: failed to push some refs to '[email protected]:NAMEtaylor/tabtrack.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    
    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master)
    $ git push origin master
    Enter passphrase for key '/c/Users/NAME/.ssh/id_rsa':
    To [email protected]:NAMEtaylor/tabtrack.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to '[email protected]:NAMEtaylor/tabtrack.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    
    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master)
    $ git push origin bridge
    Enter passphrase for key '/c/Users/NAME/.ssh/id_rsa':
    error: unable to resolve reference refs/remotes/origin/bridge: No error
    error: Cannot lock the ref 'refs/remotes/origin/bridge'.
    Everything up-to-date
    
  6. I tried to git push -f but:

    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (bridge)
    $ git checkout master
    Switched to branch 'master'
    
    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master)
    $ git push -f
    warning: push.default is unset; its implicit value is changing in
    Git 2.0 from 'matching' to 'simple'. To squelch this message
    and maintain the current behavior after the default changes, use:
    
      git config --global push.default matching
    
    To squelch this message and adopt the new behavior now, use:
    
      git config --global push.default simple
    
    See 'git help config' and search for 'push.default' for further information.
    (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
    'current' instead of 'simple' if you sometimes use older versions of Git)
    
    Enter passphrase for key '/c/Users/NAME/.ssh/id_rsa':
    Counting objects: 13, done.
    Delta compression using up to 2 threads.
    Compressing objects: 100% (7/7), done.
    Writing objects: 100% (7/7), 898 bytes | 0 bytes/s, done.
    Total 7 (delta 5), reused 0 (delta 0)
    To [email protected]:NAMEtaylor/tabtrack.git
    
    • 1297c9f...bfa60d5 master -> master (forced update) error: unable to resolve reference refs/remotes/origin/bridge: No such file or d irectory error: Cannot lock the ref 'refs/remotes/origin/bridge'.
    NAME@**** /C/Users/NAME/Documents/GitHub/tabtrack (master) $ git status On branch master nothing to commit, working directory clean
  7. Finally I tried to git push origin bridge --verbose as per advice on some stackoverflow questions:

    $ git push origin bridge --verbose
    Pushing to [email protected]:ishaantaylor/tabtrack.git
    Enter passphrase for key '/c/Users/Ishaan/.ssh/id_rsa':
    To [email protected]:ishaantaylor/tabtrack.git
     = [up to date]      bridge -> bridge
    updating local tracking ref 'refs/remotes/origin/bridge'
    error: unable to resolve reference refs/remotes/origin/bridge: No error
    error: Cannot lock the ref 'refs/remotes/origin/bridge'.
    Everything up-to-date
    

A screenshot of my git tree is shown by clicking the link below (I need more rep to post a functioning pic): http://i.imgur.com/FN9wHdi.jpg

Please let me know if I need to add any other information in the question for it to become better. Thanks so much for your time, even if you just read my problem!

like image 850
Ishaan Taylor Avatar asked Feb 25 '14 07:02

Ishaan Taylor


People also ask

How do I fix broken references in git?

Solution. Unsure the root cause of the "reference broken". To fix it, delete this file . git/refs/remotes/origin/master , and git fetch to retrieve it back.

How to fetch the remote branch in git?

To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands. If you approve the changes a remote branch contains, you can merge it into a local branch with a normal git merge .

Can not lock ref git pull?

Clean up and optimize local repository Run the following command to optimize your current repository. If it didn't work, you can remove . git/logs/refs/remotes/origin/branch and . git/refs/remotes/origin/branch then try again, as a few users reported that it works for them.

What is fetch and pull in git?

Git Fetch is the command that tells the local repository that there are changes available in the remote repository without bringing the changes into the local repository. Git Pull on the other hand brings the copy of the remote directory changes into the local repository.


1 Answers

First, set the default push policy:

git config --global push.default simple

Then you can try and push your master branch

git push -u -f origin master

(you shouldn't need your bridge branch, since you merged master in it, and merge that branch back to master in point 4)

like image 194
VonC Avatar answered Oct 30 '22 13:10

VonC