Skip to content

Instantly share code, notes, and snippets.

@gangstead
Created November 16, 2021 22:43
Show Gist options
  • Save gangstead/b2b25475b435422ae8d55a87a1677622 to your computer and use it in GitHub Desktop.
Save gangstead/b2b25475b435422ae8d55a87a1677622 to your computer and use it in GitHub Desktop.
So you've committed to main, but your main is behind origin main and the push gets rejected...
➜ git commit -am "my commit to main"
[main 10bc4d8] my commit to main
1 file changed, 11 deletions(-)
➜ git push
To github.com:myorg/myrepo.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'github.com:myorg/myrepo.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.
➜ git checkout -b blah
➜ git checkout main && git reset --hard origin/main && git pull && git checkout blah && git rebase main && git checkout main && git merge blah && git branch -d blah
➜ git push
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 16 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 444 bytes | 444.00 KiB/s, done.
Total 5 (delta 4), reused 1 (delta 1), pack-reused 0
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To github.com:myorg/myrepo.git
6fbfb47..87a0639 main -> main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment