0

I'm trying to delete files within a folder in git using git bash and its not working properly.

I want to delete all files within a folder without deleting the folder itself and doing all of this from outside of the folder.

CosmicGiant
  • 6,275
  • 5
  • 43
  • 58
Ariel Einfeld
  • 127
  • 1
  • 6
  • 2
    Git does not care about folders (i.e., they do not need to be created or deleted). They just exist if there are files in them. So you probably might as well delete the folder – Bastian Voigt Jul 08 '15 at 18:44
  • 1
    Yeah, Git doesn't explicitly track folders (you can't commit them directly). This is why you often see placeholders like .gitkeep or empty .gitignore files inside of empty directories. – Chris Rasys Jul 08 '15 at 18:51
  • possible duplicate of [git and empty folders](http://stackoverflow.com/questions/1767165/git-and-empty-folders) – cincodenada Jul 08 '15 at 19:05

1 Answers1

1

Git Bash uses UNIX commands. To delete all the files within a directory from outside the directory (say it is named dirName) use:

rm -f dirName/*

The -f option forces deletion, so that your shell will not request confirmation for every file you want to delete. See the rm man page for more info on rm options and such.

Caden Depatie
  • 126
  • 1
  • 4
  • when doing rm -f it switches the files to: "Changes not staged for commit:" and so i cant commit the change and delete them from the remote repository – Ariel Einfeld Jul 08 '15 at 19:24
  • sorry - when doing git rm -f it also deletes the directory and i wish to keep the directory – Ariel Einfeld Jul 08 '15 at 19:31
  • not git rm, just rm. Also, as others mentioned in the comments on your question, git will not track an empty directory. If you want to maintain the empty directory in your remote repo, add an empty .gitignore file to the directory, and then use `git add` to stage your changes for commit. – Caden Depatie Jul 08 '15 at 19:33