Last active
October 27, 2021 18:02
-
-
Save OmeGak/5481323 to your computer and use it in GitHub Desktop.
Fix for cleaning a repository when: "error: Couldn't set refs/heads/branchName"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Solves: | |
# error: Couldn't set refs/heads/branchName | |
# To X:xxx.git | |
# ! [remote rejected] branchName -> branchName (failed to write) | |
# error: failed to push some refs to 'X:xxx.git' | |
git fsck --unreachable | |
git reflog expire --expire=0 --all | |
git repack -a -d -l | |
git prune | |
git gc --aggressive |
I had the same problem. I quit Google Drive and did a 'git push' and it worked. So there is some workaround at least.
I find myself having to do this on every commit if its been more than like, 5 minutes. Is there a permanent fix? ( i am not suing google drive or anything). Furthermore, I find this corrupts my history and makes lal my commits look like they were at once.
I have been having this issue a lot, with remote stored in a network drive. Apparently local refs have drifted from remote. The tip from the ohshitgit guide is useful (https://ohshitgit.com/), in all cases it has solved my problem, as long as it is ok to reset local:
git reset --hard origin/branchName
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just a warning to anyone else that finds this - the double dashes have been converted to long single dashes above. It should be:
In any case, this didn't work for me. The problem seemed to be that the reference to HEAD in my remote was wrong.
I updated
REMOTE: .git/refs/heads/master
to be the same as
LOCAL: .git/refs/heads/master
and everything worked again. I'm using Google Drive to store repos.
EDIT: but the next time I made a commit and tried to push it, I'm back to the same error