An interactive shell for git
Ruby C M4 Makefile Shell
Latest commit 6fd2488 Jan 6, 2017 @georgebrock georgebrock Refactor from runners to input strategies.
This commit replaces the `Gitsh::InteractiveRunner` and
`Gitsh::ScriptRunner` classes with input strategies
(`Gitsh::InputStrategies::Interactive` and `Gitsh::InputStrategies::File`).
Previously each runner class's `#run` method would loop over available input
and pass each command to the interpreter. Now the interpreter controls the
loop and asks the strategy for commands.

The main motivation is to support multi-line constructs. We would've needed
to add very similar code for handling incomplete input to both the runner
classes. Now that the interpreter is responsible for controlling to overall
flow of the session, we'll be able to handle incomplete input in one place.

A nice side-effect is that the `Gitsh::CLI` code is cleaner, and now uses
conditionals to create different strategies instead of using conditionals to
fork the control flow.

This commit also introduces some new `Gitsh::*Runner` classes, which take
over responsibility for the places where we still need to execute some gitsh
code outside of the main run loop:

* The old `Gitsh::ScriptRunner` class was used to load the `.gitshrc` file
  at the start of an interactive session, and by the internal `:source`
  command.  This has been replaced with a `Gitsh::FileRunner` that handles
  setting up a `Gitsh::InputStrategies::File` and a `Gitsh::Interpreter` for
  a given file.

* Similarly, the old `Gitsh::Interpreter#execute` method was used by
  `Gitsh::Arguments::Subshell` to run the contents of a subshell. This has
  been replaced with a `Gitsh::StringRunner` and associated


The gitsh program is an interactive shell for git. From within gitsh you can issue any git command, even using your local aliases and configuration.

For a quick introduction to gitsh, watch our video on Upcase.

Build Status Code Climate

Why should you use gitsh?

  • Git commands tend to come in groups. Avoid typing git over and over and over by running them in a dedicated git shell:

    sh$ gitsh
    gitsh% status
    gitsh% add .
    gitsh% commit -m "Ship it!"
    gitsh% push
    gitsh% ctrl-d

  • Hit return with no command to run git status (change this command by setting gitsh.defaultCommand via git config; remember it will be prefixed with git), saving even more typing:

      gitsh% ⏎
      # On branch master
      nothing to commit, working directory clean
  • Easily execute shell commands:

    gitsh% !echo Hello world
    Hello world
  • Combine commands with &&, ||, and ;:

    gitsh% commit && push
  • Make temporary modifications to your git configuration with gitsh config variables. These changes only affect git commands issued in this gitsh session and are forgotten when you exit, just like shell environment variables.

      gitsh% :set 'George Brocklehurst and Mike Burns'
      gitsh% :set
      gitsh% commit -m 'We are pair programming'
  • Access information about your repository with magic variables like $_rebase_base, $_merge_base and $_prior.

      gitsh% rebase master
      CONFLICT (content): Merge conflict in db/schema.rb
      gitsh% checkout $_rebase_base -- db/schema
      gitsh% !rake db:schema:load db:migrate
  • Tab completion for git commands, aliases, and branches without modifying your shell settings, and without any extra setup for aliases and third party git commands.

  • Information about the state of your git repository in the prompt, without modifying your shell settings. This includes the name of the current HEAD, and a colour and sigil to indicate the status.

  • It works with hub and gh:

    sh$ gitsh --git $(which gh)
    gitsh% pull-request

Installing gitsh

See the installation guide for install instructions for other operating systems.

Contributing to gitsh

Pull requests are very welcome. See the contributing guide for more details.

Similar projects

  • git-sh - A customised bash shell with a Git prompt, aliases, and completion.
  • gitsh - A simple Git shell written in Perl.
  • repl - Wraps any program with subcommands in a REPL.


gitsh is Copyright © 2016 Mike Burns, George Brocklehurst, and thoughtbot. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About thoughtbot


gitsh was created by thoughtbot's Stockholm software development team and continues to be maintained and funded by thoughtbot. The names and logos for thoughtbot are trademarks of thoughtbot, inc.

We love open source software! See our other projects. We are available for hire.