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
~/.bashrcautomatically in the next time you open Git bash, you can put content~/.bash_profileinstead of~/.bahsrcor create~/.bash_profilewith 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
.exefile under Git’susr/binfolder. - Method 2: Add the command’s
.exefile to thePATHenvironment variable. This enables the new command available for all terminals.
Note: You may noticed that
mingw32/bin/mingw64/binunder Git also holds packages. If you finishes the post, maybe it’s better to put.exeinusr/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
curlwhich 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
makefor it
Note: As New utilities to Git bash mentioned, sometimes the windows binary have funny prefixes, so you should rename the
.exefile 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.
batto replacecat.batoffers highlight, paging, even file concatenation.diff so fancyto replacediff.diff-so-fancygives me both color coding but also character highlight of changes.fdto replacefind.fdis easier to use, such asfd jsis used to find files with filenames containingjs.
- 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
- Unix style terminals for Windows:
- Git for Windows
- Cmder, a handy and portable terminal for Windows.
- Cygwin, with more utilities than Git for Windows from GNU and other projects.
Package manager for Windows
- Scoop A command-line installer for Windows. It requires PowerShell 5 (or later, include PowerShell Core) and .NET Framework 4.5 (or later)
$ 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+.