How to Dry Run Git Commands?

In our daily routine, testing is a compulsory feature to check the expected results. Comparatively, Git also provides a feature to test its commands called dry run for getting the output information of the specific command. For that purpose, Git offered a “–dry-run” flag.

The outline for this write-up is:

How to Dry Run Git Commands?

As we described above to dry run the Git commands, there is a “–dry-run” built-in flag that can be used with commands to display expected outcomes. Please note that not every command supports the “–dry-run” flag but few do. Without any delay, let’s dive into the practical examples.

Example 1: Dry Run the “git add” Command

If you want to know, what changes will be applied to the tracking index after executing the “git add” command. Then, dry run this particular command along with the “–dry-run” flag as shown:

git add . --dry-run

The output of the command indicates there is a “file5.txt” file in the working directory that will need to track:

Example 2: Dry Run the “git commit” Command

The “git commit” is a command considered to save the new changes in the current repository. To dry run the “git commit” command, use the following command:

git commit --dry-run

The output shows that the working tree area is clean and there is nothing to commit. To commit the changes, we need to track the file:

Example 3: Dry Run the “git clean” Command

Likewise, the “git clean” command is utilized to remove the unnecessary files in the repository. To dry run the “git clean” command, run the following command:

git clean -df --dry-run

The output shows that the command will remove the “file5.txt” available in the current directory:

Example 4: Dry Run the “git push” Command

Similarly, the “git push” command pushes the project to the defined repository of GitHub. To dry run the “git push” command, use the below-mentioned command:

git push --dry-run

The resultant output shows that the command will push the content of the current directory to the given HTTPS link of the GitHub repository:


To dry run the Git commands, use the “–dry-run” flag with the desired command. Keep in mind, there are only a few commands that support the “–dry-run” flag. For example, to dry run the “git push” command execute “git push –dry-run”. This guide has covered various examples to dry run the Git commands.

About the author

Abdul Mateen

I hold a bachelor's degree in Computer Science and have a good technical background. As an author, I break down technical concepts in a clear and concise manner. Learning new skills and exploring new technologies is my passion.