Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Introduction to Git Managing Committed Files Removing Files

Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
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 :)