Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to properly handle GIT branch is ahead of 'origin/master' by X commits [duplicate]

Tags:

git

github

P.S: Please note that i have read almost all other related questions about this but it still not working at all.

I have the following issue on master branch:

git status

On branch master
Your branch is ahead of 'origin/master' by 5 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

after reading most of the articles here about this case and asking the company i work for, i am not allowed to:

rebase

or use

git fetch origin git reset --hard origin/master

so i tried:

git fetch origin
git pull

but i have the same result after doing git status

What should i do to fix my local master branch exactly?

my goal:

  • not to push because i am on master

  • get rid of the current commit without affecting master branch

like image 442
John D Avatar asked Oct 15 '25 20:10

John D


1 Answers

To roll back 5 commits locally to keep in sync with remote master branch, you can do this:

git reset --hard HEAD~5

Or run git log and reset to the HEAD commit of origin/master

git reset --hard <commit id>

You could also just reset to origin/master

git reset --hard origin/master
like image 196
RoadRunner Avatar answered Oct 18 '25 10:10

RoadRunner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!