2

I understand it is possible to delete everything locally and just start fresh but I wonder if there is an easier way when you do not require to keep anything done locally using git commands.

for example if I added bunch of files locally that I would like to remove and just download the latest master copy.

Please note: Reading the other questions (there are many; I read them before posting), git help & blog posts I wasn't sure if it's going to reset my repository or not which is why I posted this question; I imagine someone with the same exact issue might want to validate and that's what I have done through comments. and that is why I don't think its a duplicate although it might have the same response.

7
  • 1
    Something like git reset --hard?
    – Marvin
    Jan 19, 2016 at 23:28
  • Also git clean -dfx && git pull origin master
    – Whymarrh
    Jan 19, 2016 at 23:29
  • You can git rm to get rid of everything Jan 19, 2016 at 23:29
  • I seen this; but didn't try it because I do not want to make any changes to my repo.
    – Ash
    Jan 19, 2016 at 23:30
  • okay so I git rm and git pull origin master ? git rm is not going to delete my master copy in the cloud ?
    – Ash
    Jan 19, 2016 at 23:32

1 Answer 1

8

To remove the git commit which you have added locally do:

git reset --hard HEAD^

To remove the remove the uncommitted files, do:

git clean -fd

check out other git Clean options here:

https://git-scm.com/docs/git-clean

and then do

git fetch
git rebase origin/master

or

   git pull
2
  • I did git reset --hard HEAD^ and my head went back to one before my last commit, is that what is suppose to happen ?
    – Ash
    Jan 19, 2016 at 23:36
  • if You have committed your changes use the first command else use the second one..
    – insomiac
    Jan 20, 2016 at 5:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.