Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of local commits in git?

Tags:

git

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?

like image 441
Tomasz Błachowicz Avatar asked Mar 25 '11 09:03

Tomasz Błachowicz


1 Answers

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.

like image 187
Laurent Pireyn Avatar answered Oct 21 '22 00:10

Laurent Pireyn