Development Tools Introduction to Git Managing Committed Files Removing Files

Jamie Reardon
Jamie Reardon
Treehouse Project Reviewer

What about removing files out of a subdirectory?

So I understand about the git rm subcommand removing files, but what I encountered is that if I had folders inside of my git repo, if I remove any files inside of those folders, the whole folder is also removed? How do I keep the folders but only remove the files?

Thanks.

1 Answer

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

Git will not track an empty folder. If you have a folder that you want to keep, try creating and committing a file named .gitkeep inside it.

Jamie Reardon
Jamie Reardon
Treehouse Project Reviewer

Hey Jay, I actually found out on workspaces that if I have more than one file in a subdirectory, then it will only delete the file with the command: git rm.

If you have only one file, then the entire subdirectory with that file will be deleted. I shown this to Brian Jensen in the slack app of the techdegree and he found it weird behaviour.

Jay McGavren
Jay McGavren
Treehouse Teacher

Jamie Reardon Weird, perhaps, but that's the standard Git behavior. git rm mydir/a.txt removes mydir on my Mac as well.

Jamie Reardon
Jamie Reardon
Treehouse Project Reviewer

Ah I see, didn't know that as I didn't see you mention it on the videos. Thanks for the clarification! I have finished this course and I enjoyed it thoroughly, I am now studying the expanded course of the Git: Branches and Merging by yourself. Thanks :)