Skip to content

Instantly share code, notes, and snippets.

@OmeGak
Last active October 27, 2021 18:02
Show Gist options
  • Save OmeGak/5481323 to your computer and use it in GitHub Desktop.
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"
# 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
@santiago-salas-v
Copy link

santiago-salas-v commented Oct 27, 2021

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