71

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?

0

3 Answers 3

161

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.

4
  • 4
    It'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, 2015 at 20:07
  • 5
    rmdir /s /q .git on windows
    – shoe
    Aug 20, 2017 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 ! Dec 10, 2017 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 : man7.org/linux/man-pages/man1/rm.1.html
    – Morgan
    Dec 13, 2017 at 10:03
10

If you want to create the repository again, then just remove the .git directory.

1
  • This, then you are free to start afresh with git init
    – UrbanConor
    Sep 17, 2020 at 15:18
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?

3
  • 1
    Very bad idea since it pulls the code from remote repository. Oct 19, 2015 at 13:36
  • 3
    WARNING 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. Jul 20, 2020 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 1, 2022 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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