The Mijingo Blog

Latest news, updates, free tutorials, and more from Mijingo.

Dry Run Before Adding to Git Repository

by Ryan Irelan

One focus in my Git classroom training is to give my students the knowledge and power to fix things when something goes wrong. I have an entire section on it (as well as in my video course series.

But it’s also important to test things before you do them so you can avoid things going wrong!

One way to do that in Git is to use the --dry-run flag with git-add.

Let’s say I have a bunch of changes and I just want to check what will happen when I run git-add to stage them for commit. Unstaging a staged change isn’t a big deal but I like to avoid problems (and fixing them!) if I can.


git add . --dry-run

Using this command I’m adding all changed files (the . means everything) but I’m only doing a simulation. When this happens I’ll get a list of files that will be included in the add and staged for the next commit.

A handy tip for the next time you want to see what happens before you do it.

Filed Under: Free Tutorials, Git