12

this should be simple but i cant find the right anwer I am new to git I added a bunch of new files (not staged) to my git tree i want to just delete them without also deleting the git ignore files in that directory any commands? the

git clean -nd

command tells me it will erase all my .git ignore files as well?

Yehuda Schwartz
  • 3,378
  • 3
  • 29
  • 38

2 Answers2

6

Use -f parameter:

git clean -f
Claudio
  • 10,614
  • 4
  • 31
  • 71
6

For your case, you could give an exclude parameter:

git clean -nd -e **/.gitignore

However, normally, I think it would be recommended to do either of these instead:

  • Commit your .gitignore file. If the ignore rules are useful for everyone who uses the repo, then it makes sense to push it to the remote. git clean will not remove committed files.
  • If you have personal ignore rules, put them in the .git/info/exclude file instead of a .gitignore file. (This is a recommendation from gitignore documentation)
Alderath
  • 3,761
  • 1
  • 25
  • 43