Table of Contents

What would git do?

It's often nice to be able to check what a command would do if you were to run it, but without actually letting it do anything.

This page is basically a summary of how you get around the disappointing fact that almost all git commands have no "dry-run" option. There are so many ways in which a pretty recently-developed set of tools such as git could be so much better if only the developers had thought about the shortcomings of the commands they were already familiar with, and picked out the best bits, instead of just making the same mistakes all over again (along with, to be fair, a few new ones).

A single consistent "--dry-run" option for all git commands would be a wonderful feature.

So, what does git think would happen if I were to...

...just keep on editing files locally?

git status

...do a commit?

git diff
git diff --cached --name-only
git diff --cached --name-status

...do a push?

This one is an exception. It does have a "--dry-run" option!

git push --dry-run

...do a pull?

Firstly, don’t pull. Do a fetch, possibly followed by a merge or (far better if you can) a rebase. Part of the reason for not pulling is that you can do things in between the fetch and the rebase, such as finding out what would get changed if you went ahead with the second command. If the fetch tells you that your copy of the repository can be "fast-forwarded", then you can do a rebase (simpler) rather than a merge (more complex).

To get a list of the files which would be changed (added, deleted, modified, renamed):

git fetch
git diff --name-status @..@{u}

To get a list of the commit comments:

git fetch
git log --oneline ..@{u}

If you're happy with the results, you can then go ahead with a

git rebase

or

git merge

as appropriate.


Go up
Return to main index.