Appendix D. Automating TortoiseGit

TortoiseGit

Appendix D. Automating TortoiseGit

Since all commands for TortoiseGit are controlled through command line parameters, you can automate it with batch scripts or start specific commands and dialogs from other programs (e.g. your favourite text editor).

[Important] Important

Remember that TortoiseGit is a GUI client, and this automation guide shows you how to make the TortoiseGit dialogs appear to collect user input. If you want to write a script which requires no input, you should use the official Git command line client instead.

D.1. TortoiseGit Commands

The TortoiseGit GUI program is called TortoiseGitProc.exe. All commands are specified with the parameter /command:abcd where abcd is the required command name. Most of these commands need at least one path argument, which is given with /path:"some\path". In the following table the command refers to the /command:abcd parameter and the path refers to the /path:"some\path" parameter.

Since some of the commands can take a list of target paths (e.g. committing several specific files) the /path parameter can take several paths, separated by a * character.

TortoiseGit uses temporary files to pass multiple arguments between the shell extension and the main program. From TortoiseGit 1.5.0 on and later, /notempfile parameter is obsolete and there is no need to add it anymore.

The progress dialog which is used for commits, updates and many more git.exe commands usually stays open after the command has finished until the user presses the OK button. This can be changed in the settings dialog. You may use /closeonend parameter to override the this setting from your batch file.

To close the (git.exe) progress dialog at the end of a command automatically without using the permanent setting you can pass the /closeonend parameter.

  • /closeonend:0 Close manually

  • /closeonend:1 Auto-close if no further options are available

  • /closeonend:2 Auto-close if no errors

The table below lists all the commands which can be accessed using the TortoiseGitProc.exe command line. As described above, these should be used in the form /command:abcd. In the table, the /command prefix is omitted to save space.

Table D.1. List of available commands and options

Command Description
:about Shows the about dialog. This is also shown if no command is given.
:bisect Allows to control the bisect logic of TortoiseGit. Use the /start parameter to start a bisect you can specify /good:REF and /bad:REF here). When bisect is active, you can use /good, /bad and /reset to control the bisect process.
:fetch Opens the fetch dialog. Use the /remote parameter to control the remote which should be pre-selected.
:firststart Shows the first start wizard.
:log Opens the log dialog. The /path specifies the file or folder for which the log should be shown. Additional options can be set: /rev:"SHA1" highlights and automatically scrolls to the specified revision, /endrev:"SHA1/branch", shows the log of the specified revision, /startrev:"SHA1/branch" (only in combination with endrev), shows the log of the revision range startrev..endrev, /range:"gitrevision", shows the log of the entered gitrevision (e.g. "branch1...branch2"), /limit:"N SCALE", SCALE could be "Commit", "Year", "Month", "Week"; it shows last N commit(s), last N year(s), last N month(s), last N week(s). Use /limit:0 to disable any default limit. /findstring:"filterstring" fills in the filter text, /findtext forces the filter to use text, not regex, or /findregex forces the filter to use regex, not simple text search, and /findtype:X with X being a number between 0 and 127. The numbers are the sum of the following options:
  • /findtype:0 filter by everything

  • /findtype:1 filter by messages

  • /findtype:2 filter by path

  • /findtype:4 filter by authors

  • /findtype:8 filter by revisions

  • /findtype:16 not used

  • /findtype:32 filter by bug ID

  • /findtype:64 filter by subject

If /outfile:path\to\file is specified, the selected revision is written to that file when the log dialog is closed.
:clone Opens the clone dialog. The /url specifies the URL to clone from. The /path specifies the target directory to clone to. If /exactpath is not specfied, the repository name (without trailing .git) will be appended to target directory. This is the default behaviour. If /exactpath is specfied, the exact /path is considered the target directory, without appending repository name to it.
:commit Opens the commit dialog. The /path specifies the target directory or the list of files to commit. You can also specify the /logmsg switch to pass a predefined log message to the commit dialog. Or, if you don't want to pass the log message on the command line, use /logmsgfile:path, where path points to a file containing the log message. To pre-fill the bug ID box (in case you've set up integration with bug trackers properly), you can use the /bugid:"the bug id here" to do that.
:add Adds the files in /path to version control.
:revert Reverts local modifications of a working tree. The /path tells which items to revert.
:cleanup Cleans up the working tree in /path.
:resolve Marks a conflicted file specified in /path as resolved. If /noquestion is given, then resolving is done without asking the user first if it really should be done.
:repocreate Creates a repository in /path
:switch Opens the switch dialog. The /path specifies the target directory.
:export Exports a revision of the repository in /path to a zip file.
:merge Opens the merge dialog. The /path specifies the target directory.
:settings Opens the settings dialog.
:remove Removes the file(s) in /path from version control.
:rename Renames the file in /path. The new name for the file is asked with a dialog.
:diff Starts the external diff program specified in the TortoiseGit settings. The /path specifies the first file. If the option /path2 is set, then the diff program is started with those two files. If /path2 is omitted, then the diff is done between the file in /path and its BASE. To explicitly set the revision use /startrev:xxx and /endrev:xxx. Add /unified to get a unified diff. Add /line:NN to get scroll to the mentioned line.
:showcompare

Depending on revisions to compare and the path, this either shows a unified diff (if the option unified is set), a dialog with a list of files that have changed (filtered by a possibly entered subpath) or if the path point to a file starts the diff viewer for those the file in the different revisions. Use /revision1:xxx and /revision2:xxx to specify the revisions to compare, whereas /revision1:xxx indicates the base revision to compare with.

:conflicteditor Starts the conflict editor specified in the TortoiseGit settings with the correct files for the conflicted file in /path.
:help Opens the help file.
:repostatus Opens the check-for-modifications dialog. The /path specifies the working tree directory.
:repobrowser Starts the repository browser dialog, pointing to the working tree given in /path. An additional option /rev:xxx can be used to specify the revision which the repository browser should show. If the /rev:xxx is omitted, it defaults to HEAD.
:ignore Adds all targets in /path to the ignore list, i.e. adds file(s) to the .gitignore file.
:blame

Opens TortoiseGitBlame for the file specified in /path.

If the option /endrev is set TortoiseGitBlame ends at that revision.

If the option /line:nnn is set, TortoiseGitBlame will open with the specified line number showing.

:cat Saves a file from an URL or working tree path given in /path to the location given in /savepath:path. The revision is given in /revision:xxx. This can be used to get a file with a specific revision.
:pull Opens the pull dialog in the working tree located in /path.
:push Opens the push dialog in the working tree located in /path.
:rebase Opens the rebase dialog for the working tree located in /path.
:stashsave Opens the stash save dialog for the working tree located in /path. A prefilled mesage can be achieved by using the /msg parameter.
:stashapply Applies to latest stash to the working tree located in /path.
:stashpop Applies to latest stash to the working tree located in /path and drops the latest stash entry.
:subadd Opens the submodule add dialog. /path.
:subupdate Opens the submodule update dialog for and filters the submodules regarding the folder /path.
:subsync Syncs the submodule information for the working tree located in /path.
:reflog Opens the reflog dialog for the repository located in /path.
:refbrowse Opens the browse references dialog for the repository located in /path.
:updatecheck /visible: Shows the dialog even if no newer TortoiseGit version is available. /force: Shows file list for download even if the latest TortoiseGit has been installed.
:revisiongraph Shows the revision graph for the repository given in /path.

To create an image file of the revision graph for a specific path, but without showing the graph window, pass /output:path with the path to the output file. The output file must have an extension that the revision graph can actually export to. These are: .svg, .wmf, .gv, .png, .jpg, .bmp and .gif.

:daemon Launches the Git Daemon for the repository given in /path.
:pgpfp Prints the TortoiseGit Release Signing Key fingerprint. If you trust the current TortoiseGit installation, this can be used as a trust anchor to future releases.
:tag Opens the Create Tag dialog. The /path specifies the repository folder. Additional options can be set: /rev:"ref" tags on the specified ref/commit, /name:"tag_name" fills the Tag name in Create Tag dialog.

Examples (which should be entered on one line):

TortoiseGitProc.exe /command:commit
                 /path:"d:\git_wc\file1.txt*c:\git_wc\file2.txt"
                 /logmsg:"test log message" /closeonend:2

TortoiseGitProc.exe /command:log /path:"c:\git_wc\file1.txt"
                 /startrev:master~100 /endrev:master

[Tip] Tip

When calling TortoiseGit from within the msys environment, you can also use more *nix style command line parameters:

TortoiseGitProc.exe -command commit
                    -path "d:\git_wc\file1.txt*c:\git_wc\file2.txt"
                    -logmsg "test log message" -closeonend 2