0

I want to revert the state of my local git repository to pristine state i.e. as good as newly cloned repository.

Is there a single command in command which will sync my local repository with base (like git pull --rebase) but will also :

  1. Remove any local temporary files created.
  2. Revert any changes in files.
  3. Un-stage / Undo any local commits.

If there is not a single command, would there be a better way to do it other than git pull --rebase ; git clean -f.

ViFI
  • 971
  • 1
  • 11
  • 27
  • I am not clear with your requirement. Do you want to keep your local commits but want what is latest on Remote repository?? – Abhijeet Kamble Jun 27 '16 at 07:18
  • @AbhijeetKamble : I am expecting the local repository to be as good as newly cloned repository so want local changes to be reverted as as well. – ViFI Jun 27 '16 at 07:25
  • Why do you need that? I have a feeling this might be a XY problem... – CptBartender Jun 27 '16 at 07:31
  • @CptBartender : It is a python repository. Running unit tests locally is leaving a lot of log files which i need to clean up everyday as first thing in morning. I wanted to combine the steps " repo update ; clean temporary files " and sometimes also clean up local changes. So thought of combining this into one alias but before doing so wanted to check if git already provides something similar as single command. I am new to git. – ViFI Jun 27 '16 at 07:58
  • @ViFI: do you have .gitignore file in your repository?? – Abhijeet Kamble Jun 27 '16 at 08:03
  • @ViFI: check this http://stackoverflow.com/questions/1753070/git-ignore-files-only-locally – Abhijeet Kamble Jun 27 '16 at 08:24

2 Answers2

1

Use the below command

git reset --hard
Twinkle
  • 514
  • 3
  • 8
1

If your remote repository has changed, then you'll need to fetch, and then you can reset to that state.

git fetch origin
git reset --hard origin/master
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167