Git update tip: git add and git remove with one step

At Crowd Favorite we keep a github mirror repo of several plugins that we integrate into client sites; this helps w/ our workflow as we can utilize git submodules for the plugins.

When upgrading a plugin, it’s easiest to rm * the contents of the plugin (besides the .git folder) and then svn export --force {url to the repo} ..  The one potentially troublesome issue is that some files may remain removed while others are modified and yet other files could be added.

While upgrading to the latest version of Jetpack by Automattic, that was the case with many files.  In a good developers effort to be lazy, I thought there must be a way to tell git to git add the modified files, and git rm the deleted files without me having to do it by hand.  Here comes git add -u (git add --update) which does just that (for the files that git’s tracking).

So instead of having to take action against 308 individual files in either one giant command to add, and another to remove, and then another to add the new files, I was able to accomplish what I needed in two steps:

  1. git add -u
  2. git add .

Secondary moral of the story: read man pages.