Let be honest, I ran into difficulties with my git repository. I've been working on the same project from two different machines (say at work and at home). There is also remote repository (origin
) where I keep the master copy of the code.
At the beginning I cloned the repository form origin master
and started new branch (newfeature
). On daily basis when I'm done with changes at work I push my commits from the branch newfeature
to origin
. The same when I work at home.
Yesterday I finished working on new feature at home, so I checked our master
and then merged newfeature
branch. Everything went grand so I pushed my new master
branch to origin
and then deleted newfeature
branch locally and on remote. Earlier today at work I checked out master
that now contains new feature merged. When I run git status
now it says that there is nothing to commit, but also my local branch master
is ahead of origin master
by 38 commits.
How can I get rid of any of those local commits that are ahead as I know that origin master
has the latest code?
You should reset your master
branch on origin/master
:
git checkout master
git reset --hard origin/master
Warning: A hard reset will discard all the changes in your working copy and make it exactly like it was in origin/master
.
If I didn't get your question right, or you have second thoughts, remember that git reflog
is your friend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With