I have a problem when i try to push my local commits, it has probably happened when Android Studio has crushed. Here is the error:
update_ref failed for ref 'refs/remotes/origin/master': cannot lock ref 'refs/remotes/origin/master': unable to resolve reference refs/remotes/origin/master: Invalid argument
$git stash
says that HEAD
is now at my latest commit.
I'm still a beginner in git and I have no idea how to fix it.. What can I do?
How to Fix error: failed to push some refs to Error in Git Using git pull. To send a pull request means to "fetch" new changes made to the remote repo and merge them with the local repo. Once the merging is done, you can then push your own code changes to GitHub.
This means that someone else pushed a commit to the same branch you're pushing to, but you don't have that commit on your laptop yet. This can happen if it has been awhile since you ran "git pull" on a branch that many people contribute to, such as staging. To fix this issue, run: git pull origin <your-branch>
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.
Origin is simply the name given to any remote repository available on GitHub. Whenever we need to push the changes to a remote repository, we use git push along with the remote repository “origin” and “master” branches. The term used is “git push origin master“.
Your refs/remotes/origin
directory—this is a directory within in your local repository—has some sort of problem. (It's not clear to me what exactly went wrong, but your guess that it happened when Android Studio crashed seems likely to me as well.)
To fix it, you can probably use the sequence of commands below. Note that I don't recommend it in general—your Git service, whether that's Android Studio or ordinary command-line Git, is not supposed to crash and leave you with a broken repository, so you should never have to do this, it's just an emergency repair, something like putting duct tape all over your car1 after a tree fell on it, just enough to get you to a proper repair / replacement vehicle later:
$ cd $(git rev-parse --show-toplevel) # if necessary
$ rm -rf .git/refs/remotes/origin # remove all origin/*
$ mkdir .git/refs/remotes/origin # create empty origin/
$ git fetch origin # repopulate origin/*
In any case it's likely that your git push
has actually succeeded at this point, since what is failing is the update to your origin/master
remote-tracking branch.
Your Git has just finished talking to another Git on origin
, giving them (the users of origin
) updates for their master
, and origin
has accepted those updates, and your Git is now recording the fact that, the last time it talked with origin
, their master
was set to some particular commit hash—the one you just pushed.
(Remember that your origin/*
remote-tracking branches are just recording, for you, what your Git saw that their Git has for its branches. Your Git updates these when you run git fetch
, where your Git talks to their Git and gets all of its branches. Your git also updates some—not all—on git push
, when your Git talks to their Git and asks them to set one or more branches, to the hashes your Git hands them.)
1Except that as a Git mechanic, instead of just duct tape, baling wire, and chewing gum, my recommended parts are actually proper body panels, belts and hoses, and clamps. :-)
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