Blog

When removing several items from a git repo, especially if you have deleted them through the operating system, you won't have the time or the inclination to remove them through multiple single statements. Your friend here is to wildcard the directory in the git rm statement using --cached. Yes that's a double dash, but wordpress shows it as one.

Consider the following in a 'nix system:

sudo rm -R images/*

This would remove all the files in the images directory. Similarly in git this command:

git rm -r images/.

This would remove all the files in the images directory using git. What you want here is to be able to only remove the items from the git repo that have been staged for removal by having removed them from the command line or gui environment. Use this:

git rm -r --cached images/.

This has the added benefit of staging the remove for the upcoming commit. If you have the git coloring enabled like in this example on the git-svn crash course site, you'll see the files move from a red coloring to a green coloring. This can be a handy way to determine what changes have been made. Just run the git status command in between stages until you are comfortable with how they change.

git status

To enable coloring run these commands. Note that these are per repository and do not take effect for the whole machine. If you pull a repo for another machine you will need to add them to the preferences by running them for that machine's repo instance

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
#CDS > span:nth-child(1) > strong:nth-child(2)