Skip to content

Instantly share code, notes, and snippets.

@seLain
Last active January 30, 2024 19:45
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save seLain/8bdf12c7196f3fccafdf067dec2696b2 to your computer and use it in GitHub Desktop.
Save seLain/8bdf12c7196f3fccafdf067dec2696b2 to your computer and use it in GitHub Desktop.
Fix the thing GitHub keeps saying “This branch is X commits ahead, Y commits behind”
ref stackoverflow:
https://stackoverflow.com/questions/41283955/github-keeps-saying-this-branch-is-x-commits-ahead-y-commits-behind
works by
1. git remote add upstream https://github/upstream/repo.git
2. git pull --rebase upstream master
2.1 git rebase --skip (if the conflicts are not true, skip the patches)
3. git push --force-with-lease origin master
If there are branches to fix
4. git checkout myfeature
5. git rebase master
6. git push --force-with-lease origin myfeature
=== If the above does not seem work ===
1. in your local master branch (or other branch that went wrong)
2. git rebase -i <commit-id> (the commit id should be the last id before the "base" id you want to rebase to)
3. squash or drop the redundant commits, leave only the first commit maybe (the first commit should be the base id you like to rebase to)
4. wq save and apply this rebase
5. git pull --rebase upstream master
6. git push --force-with-lease origin master
done !!
@PavitKaur05
Copy link

Thanks! It helped :)

@HaoES
Copy link

HaoES commented Apr 8, 2021

thank you!

@LucyJimenez
Copy link

Great, works for me!

@eshenayo
Copy link

Excellent, thanks!

@toandaominh1997
Copy link

Work fine, Thanks so much

@rroupski-splunk
Copy link

You saved my life, thank you!

@cfpenton
Copy link

thanks!

@rokibhasansagar
Copy link

After editing and merging PR's from Upstream from time-to-time, my Forked repository is now XX commits ahead.
I'm wondering, is there any way to squash all the extra commits that I've done so that it would say that my repository is just 1 commit ahead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment