I was trying to ignore some folders when pushing and ended up with only the .gitignore
in the repository. Now want to "reset" my repository (by reset I mean to remove all the rules I applied and clean the commit area), so that I can add all my files and remove the folders I don't want after that. Any help?
Asked
Active
Viewed 1.1e+01k times
69

Bleeding Fingers
- 6,993
- 7
- 46
- 74

Wosh
- 1,565
- 2
- 17
- 30
3 Answers
158
You could just delete your .git folder and start again.
rm -rf .git
git init
This will leave the current .gitignore in place, which would still be followed by the new git repo. The .gitignore could be removed, or delete the contents so it is a blank file.

Morgan
- 19,934
- 8
- 58
- 84
-
4It's too bad that this is the only way of doing this. It would be great if there were a -f flag for `git init` to do it. – B Seven May 24 '15 at 20:07
-
4`rmdir /s /q .git` on windows – shoe Aug 20 '17 at 23:55
-
@Morgan Hey, I know I'm late, what does "-rf" stand for here? I can't find any help about that on the internet ! – DevMoutarde Dec 10 '17 at 13:29
-
2@DevMoutarde the -r is recursive (ie all sub folders and files), -f is force so will not ask about readonly files etc. more info see : http://man7.org/linux/man-pages/man1/rm.1.html – Morgan Dec 13 '17 at 10:03
10
If you want to create the repository again, then just remove the .git directory.

lukassteiner
- 787
- 1
- 6
- 25
2
If you do not need a clean history just remove the files from the repository and commit your changes. If you would like to revert to an earlier commit there is a git reset command
git reset --hard HEAD^
Here is some more info How to undo last commit(s) in Git?
-
1
-
3WARNING to non expert users: be very careful with this command and only use when you are 100% sure about what you are doing. This deletes all untracked files and depending on your particular case could be really DESTRUCTIVE. Don't use lightly. – rbndeveloper Jul 20 '20 at 15:30
-
@rbndeveloper Of course you need to know what you are doing, but that applies to GUI users too, only press the buttons you understand. I use and recommend the command line tools and their man pages. – Simson Nov 01 '22 at 22:26