Make Git Bash on Windows a better terminal

There are some things that you can do to make Git bash on Windows a powerful and easy-to-use terminal. In fact Git bash on Windows is more than just a terminal, there’s many. Although there have been a few wonderful solutions for replacing the Windows command terminal, such as Cygwin or Cmder, but you may don’t want another new terminal.

The things to make Git bash better include adding aliases for quick typing and navigation, adding new commands for new utilities, etc.

Add aliases for quick typing, navigation, automation

You probably have added commonly used command aliases to Git bash, if you haven’t, check useful git aliases. There are some other general aliases you can add.

Quick navigation your file system tells how to navigate quickly to a directory by adding some aliases (including how to do that for Git bash on Windows). With these aliases, you can jump into a directory with just a few keystrokes rather than drilling through the deep folder hierarchies.

A quick view:

# Add an alias "jhello" to git bash for quickly jumping into hello-php/ folder
$ echo "alias jhello='cd /d/programs/php/hello-php/'" >> ~/.bashrc

# Make the new added alias take effect immediately
$ . ~/.bashrc
# Jump to hello-plugin/ folder
$ jhello
$ pwd
/d/programs/php/hello-php

To add an alias for a path which contains special characters like Program Files (x86)/, just use ' to quote the special part. Below is an example in ~/.bashrc:

alias jgit="cd /d/'Program Files (x86)'/Git/"

Or you can use echo command to add this alias to ~/.bashrc

$ echo "alias jgit=\"cd /d/'Program Files (x86)'/Git/\"" >> ~/.bashrc

Note:

Depending your Git for Windows version, if it does not read ~/.bashrc automatically in the next time you open Git bash, you can put content ~/.bash_profile instead of ~/.bahsrc or create ~/.bash_profile with below content to make it reads ~/.bashrc.

> if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
> ```

> **More about quick navigation**
>
> ---
>
> Aliases for quick navigation work only for those folders that you have add their jump command aliases. [Quick navigation your file system](/tools/cmd/tools-to-quickly-navigate-your-filesystem/) also mentions an automation tool named [AutoJump](https://github.com/wting/autojump) that works for all directories, and a super cool tool named Listary for Windows. 

With this method you can add any alias for a long command, like

```shell
$ echo "alias fnf='find . -type f -name'" >> ~/.bashrc

Use aliases to automate your project work:

.bashrc

# Open a VS Code project, VS Code's 'code' CLI allows us to open up files 
# and workspaces from the command line.
# Make sure that 'code' CLI is added to "PATH" environment variable, 
# by default it is done automatially when installation.
alias vsproj='cd /c/<path>/<to>/<your>/<project>/<project_directory> && code . --new-window'

You can also add aliases for some utilities provided from an Web URL:

$ echo "alias myip='curl http://ipecho.net/plain; echo'" >> ~/.bashrc

Add new commands

There are two ways to add a new command to Git bash:

  • Method 1: Just drop the command’s .exe file under Git’s usr/bin folder.
  • Method 2: Add the command’s .exe file to the PATH environment variable. This enables the new command available for all terminals.

Note: You may noticed that mingw32/bin / mingw64/bin under Git also holds packages. If you finishes the post, maybe it’s better to put .exe in usr/bin.

New utilities to Git bash on Windows lists some utilities that you may want, but some of them are unnecessary for they have been shipped in the new Git bash for Windows or there are alternative commands.

  • xpdf is a handy utility for manipulating PDF files. download xpdf.

  • wget retrieves files using HTTP, HTTPS and FTP protocols. Note Git bash has came with curl which can downloads a file as well.

  • nano, an editor tool. Git bash 2018 includes it already.

  • make, it is not packaged with all build toolchain. Cygwin is a better choice when using make for it

Note: As New utilities to Git bash mentioned, sometimes the windows binary have funny prefixes, so you should rename the .exe file to the standard name.

And you can:

More resources

Git bash related

  • Improved command line tools list some upgraded commands that can replace the old ones for better experience. You can pick some according to your needs and add an new alias for each with the old command name.
    • bat to replace cat. bat offers highlight, paging, even file concatenation.
    • diff so fancy to replace diff. diff-so-fancy gives me both color coding but also character highlight of changes.
    • fd to replace find. fd is easier to use, such as fd js is used to find files with filenames containing js.
  • Tricks for Git bash on Windows , including:
    • How to change drive.
    • Built-in commands.
    • Open a file with Notepad++ in Git bash

Terminals for Windows

Package manager for Windows

  $ scoop install curl
  $ scoop install aria2 curl grep sed less touch
  $ scoop install python ruby go perl
  • Chocolatey. It requires PowerShell v2+ and .NET Framework 4+.
August 1, 2020 cmd git-bash

A universal document converter -- Pandoc

Pandoc is a powerful document conversion tool, it is called swiss-army knife in this field. It understands many document formats, like markdown, ms word, pdf, html, etc. And it is free, you may install it as a command tool or try it online.

cmd dev

A tool showing cheatsheet for programming languages and Linux commands

cheat.sh is a pretty useful tool that provides a cheat sheet for all you need like Linux commands, programming languages and DBMSes. You can use it to display usages of a Linux command, a code snip of a programming language like code for looping an array with PHP. For the moment, it covers 56 programming languages(C, awk, bash, PHP, Python, Perl, R, Ruby, JS, Go, Swift...) and 1000+ Linux commands.

cmd dev git-bash

Unix style terminals for Windows

If you need to run commands on Windows, it would be a much better choice to use an Unix style terminal to replace default Windows console. Here it introduces some good of them, like Git for Windows, Cmder, and a more powerful one Cygwin.

cmd