https://www.ii.com/git-bash-is-my-preferred-windows-shell/ Infinite InkUpdates Portals Git Bash Is My Preferred Windows Shell Updated by nm 2024-January-19 Page contents * News * About shells * About bash + What is Git Bash * Why I Prefer Git Bash + Communities * Managing Git for Windows and Git Bash + Installing + Launching + Inspecting + Updating + Uninstalling * Mintty customizations + Mintty color scheme + Mintty font and character set * Git Bash customizations + Display some of Git Bash's default settings + ~/.bash_profile + Aliases * Git Bash tips + Case insensitivity + Paths + The start command + Launching any app on your path + Environment variables + Scripting o Where to put scripts o Example script o No need to chmod + Unicode + Case insensitivity exceptions o --help and other command arguments o exit * See also * Endnotes * Please share & discuss * Page meta * Site meta News Ongoing According to Repology, the latest packaged Git for Windows is version [displayed at this link]. To keep up with releases of Git for Windows, which includes Git Bash and the Mintty terminal emulator, see github.com/git-for-windows/git/releases or groups.google.com/g/git-for-windows. 2023-November-18 As of today, this evolving^[1] article has been on the web for 3 years. About shells A shell is a layer or interface between you and an operating system. There are a lot of command-line shells for Windows, including: 1. COMMAND.COM, also known as "the DOS Prompt" (used in Windows 9x and earlier) 2. Cygwin 3. UWIN 4. cmd.exe, also known as CMD and "Command Prompt" 5. PowerShell^[2] 6. WSL Bash, also known as "Bash on Ubuntu on Windows" and "Bash on Windows' Subsystem for Linux"^[3] Over the years, I've used all six of the above Windows command-line shells. In 2020, I installed Git for Windows and can now add a seventh shell to the list of command-line Windows shells I've used: 7. Git Bash About bash Bash is an acronym for "Bourne again shell" and it is a command-line shell that was created for Unix-like systems. Details are at wikipedia.org/wiki/Bash_(Unix_shell). What is Git Bash Git Bash is a Windows command-line shell that is packaged with Git for Windows. It emulates the bash shell that is familiar to nix-nux users.^[4]^[5] Git Bash is useful even if you do not use git. Git Bash is not one of Windows' subsystems. When you are in !! Git Bash, you are in your regular Windows environment. And your Windows environment variables are available. Why I Prefer Git Bash I like Git Bash because... * I'm more comfortable with bash commands than CMD or PowerShell commands (because I've been using Bourne shell (sh) and friends for more than 30 years). * It's easy to install. * It has a small footprint. * It installs a Git Bash Here command that is available when right-clicking^[6] on a folder in Windows File Explorer. * I can pipe the output of commands through the less pager, which is better than the more pager.^[7] * In addition to the less command, the commands awk, cat,^[8] cd, clear, cp, curl, cut, cygpath, date, dd, diff, dos2unix, echo, file, find, git, gpg, grep and friends,^[9] gunzip, gzip, head, history, jobs, kill, ls, md5sum, mkdir, mv, mount, nano, od, openssl, perl, printenv, ps, pwd, rm, rmdir, scp, sed, sftp, sha1sum, sha256sum, sha512sum, sort, split, ssh, stat, tail, tar, tig, touch, uname, uniq, vim and friends,^[10] wc, which, whoami, xz, and more^[11] nix-nux commands are available. * I can view built-in help for a bash command with, for example, less --help or pwd --help. * Almost any app that's on my path -- including hugo, figlet, and tree.com^[12] -- can be launched either within a Git Bash script or at a Git Bash command prompt (possibly with the help of winpty ).^[13] * I can write bash or sh^[14] scripts and... + my Windows environment variables are available, + and I do not have to worry about WSL file system issues^[15] because Git Bash uses the regular Windows file system (but be aware that Git Bash uses forward-slash-delimited paths to refer to the Windows file system). * I can use output redirection (with, for example, >) to create a file that is UTF-8 Unicode text rather than Little-endian UTF-16 Unicode text, with CRLF line terminators (which is the CMD and PowerShell default encoding). Communities Git Bash has helpful communities, including: * github.com/git-for-windows/git/discussions * stackoverflow.com/questions/tagged/git-bash * stackoverflow.com/questions/tagged/git-for-windows * superuser.com/questions/tagged/git-bash * github.com/git-for-windows/git/issues?q=is%3Aissueissues?utf8=&q = Almost everything I know about Git Bash, I learned in these five communities. Managing Git for Windows and Git Bash Installing To install Git Bash, install Git For Windows, which you can download from either... * git-scm.com/downloads * or gitforwindows.org. Think carefully about what options you choose during the installation. If you are a power user, the defaults are probably not what you want. For example, I like to change the default install directory, which is C:\Program Files\Git\, to C:\Program Files\ GitForWindows\ because this helps me remember the full name of the app in this directory. Git for Windows requires Windows Vista or newer. Windows Vista was released in 2007 (~17 years ago). Launching To learn about launching Git Bash in various terminal emulators, including Mintty (which is Git Bash's default terminal emulator), see Launching Git Bash in Mintty, ConEmu, VS Code's Terminal, and Other Terminal Emulators. Inspecting To learn about the Git for Windows that you are using, run some or all of the following at a Git Bash^[16] command-line prompt: git --version git --version --build-options uname -a To see what options it was installed with, run the following at a Git Bash prompt: cat /etc/install-options.txt Updating To update Git for Windows, run the following at a Git Bash^[16] command-line prompt: git --version git update-git-for-windows git --version When you update Git for Windows... * Your home (~) directory should be preserved, but to be safe, !! back it up before you update. * Your Git Bash /etc/ and other root-level Git Bash directories will not be preserved (and ideally you should not edit these directories). Uninstalling To uninstall Git for Windows, see How to uninstall git? in github.com /git-for-windows/git/discussions. Mintty customizations Mintty is Git Bash's default terminal emulator. Details are at wikipedia.org/wiki/Mintty. Mintty color scheme Since I prefer the Solarized Light color scheme, I edited ~/.minttyrc so it includes the following. ForegroundColour=101, 123, 131 BackgroundColour=253, 246, 227 CursorColour= 220, 50, 47 Black= 7, 54, 66 BoldBlack= 0, 43, 54 Red= 220, 50, 47 BoldRed= 203, 75, 22 Green= 133, 153, 0 BoldGreen= 88, 110, 117 Yellow= 181, 137, 0 BoldYellow= 101, 123, 131 Blue= 38, 139, 210 BoldBlue= 131, 148, 150 Magenta= 211, 54, 130 BoldMagenta= 108, 113, 196 Cyan= 42, 161, 152 BoldCyan= 147, 161, 161 White= 238, 232, 213 BoldWhite= 253, 246, 227 This is the contents of the .minttyrc.light file that is part of github.com/mavnn/mintty-colors-solarized. Thank you Michael Newton (@mavnn@github.com) for making this color scheme available on GitHub! Mintty font and character set To change the character set and fonts used in the mintty terminal emulator, right click anywhere in a mintty window or title bar and choose Options. In the left pane, choose Text and then... 1. Click Select... and choose DejaVu Sans Mono, 10pt (or whatever you prefer) for the font. 2. Under Character Set, choose UTF-8 (Unicode) (or whatever you prefer). 3. Click Save These and other settings will be appended to the bottom of your ~ /.minttyrc file. Git Bash customizations Display some of Git Bash's default settings Before you customize Git Bash, check out some of its default settings by running the following four commands at a Git Bash command-line prompt. alias mount printenv set -o ~/.bash_profile If ~/.bash_profile exists, the commands in it are run each time you launch a Git Bash terminal. To create and edit this file do the following. 1. Launch a Git Bash terminal. 2. At the Git Bash command-line prompt, run one of these commands: nano ~/.bash_profile vim ~/.bash_profile Note that the TUI (terminal user interface) editors nano and vim are included in Git Bash and are on your PATH. (If you do not know how to use vim, I recommend that you use nano because, otherwise, it may take you a while to figure out how to exit vim.) 3. Add whatever commands you'd like to this file. Here is an excerpt of my ~/.bash_profile: ## Created: 2024-05-15 ## Use `gvim filename` to edit filename with GUI Vim alias gvim="/C/Windows/gvim.bat" ## Use `cdi` to cd to the Infinite Ink project root ## Note I set INFINITEINKROOT environment variable via Control Panel alias cdi="cd `cygpath $INFINITEINKROOT`" ## Do not let me overwrite a file with > redirection set -o noclobber ## Make Backspace and other things work in VS Code's & IntelliJ's terminals export TERM=cygwin # export TERM=xterm # export TERM=xterm-256color ## NOTE: All 3 of the above TERM settings work for me 4. Save your edits and close the editor. 5. At the Git Bash prompt, use the following file command to check the file type. file ~/.bash_profile This will probably display ASCII text or UTF-8 Unicode text. If either "BOM" or "CRLF line terminators" are mentioned in the output of this file command, convert it to Unix-format with one of the following commands. dos2unix ~/.bash_profile nano --unix ~/.bash_profile To learn about these commands, run the following: dos2unix --help nano --help After you change your ~/.bash_profile, I recommend that you close all Git Bash sessions and all Windows File Explorer windows, and then relaunch Git Bash and make sure your new ~/.bash_profile settings worked. Aliases To see what aliases are available, run: alias On my system, this displays: alias gvim='/C/Windows/gvim.bat' alias cdi='cd /c/Users/USERNAME/path/to/infiniteink/project/root' alias ll='ls -l' alias ls='ls -F --color=auto --show-control-chars' The first two aliases are the ones I created above in my ~ /.bash_profile. The last two are Git Bash's default aliases. Default aliases (and more) are specified in files that are located !! in the /etc/profile.d/ directory. It is best not to edit files under /etc/ because they might be replaced when Git for Windows is updated. Git Bash tips Case insensitivity Normally Unix-like shells are case sensitive, but Git Bash, in general, is case insensitive. Paths To view your current path, run the following command, which means "print working directory." pwd To go to your Git Bash home directory, which is also known as ~, run either of the following equivalent commands. cd cd ~ On most systems, your Git Bash home directory is... /c/users/USERNAME/ with USERNAME replaced with your user name. Note that in Git Bash... * The path delimiter is slash (/), which is also known as forward slash. * The C: drive is mounted as /c/. To list all mounts, run the mount command. * You can display a Windows-type path of the current working directory with pwd -W. The format of the path this command displays is sometimes called "mixed type" because it starts with a drive letter, such as C:, and uses forward slashes (/) rather than backslashes (\) as path separators. For example, this sequence of commands... cd pwd pwd -W displays... /c/Users/USERNAME C:/Users/USERNAME The start command When you are at a Git Bash prompt, you can launch a file or directory in your system's default app by using the Start command, which is equivalent to the start command (thanks to case insensitivity). Below are some examples. To open the current directory in Windows File Explorer, run: start . Notice this dot (.) To open your home directory in Windows File Explorer, run: start ~ To open your $APPDATA directory in Windows File Explorer, run: start $APPDATA To open /c in Windows File Explorer, run either of these equivalent commands: start /c start /c/ To open the parent directory of the current directory in Windows File Explorer, run: start .. To open an HTML file in your default web browser, run something like this: start ReleaseNotes.html Launching any app on your path You can launch any app that's on your path from a Git Bash prompt. For example, if Visual Studio Code is installed on your system and is on your path, you can use the following to open the current directory in VS Code. code . Notice this dot (.) Environment variables To find out the environment variables available to Git Bash, run: printenv This includes the PATH environment variable, which lists the directories that are searched for executables. Scripting I'd rather write a bash or sh^[14] shell script than a Windows batch file to deal with apps, files, and folders that live in my Windows file system. Thanks to Git Bash, It's easy to do this. (I have learned the hard way that it's not so easy to do this in WSL.^[15]) Where to put scripts When you run printenv, you can see that the ~/bin/ directory (usually /c/users/USERNAME/bin/) is on your PATH. This is a reasonable place to put your Git Bash scripts. To create this directory, run this command: mkdir ~/bin/ Example script One of my scripts is called gvim-winpath and it looks like this: #!/bin/sh ## Created: 2024-05-15 ## Filename: gvim-winpath ## Usage: gvim-winpath "C:\path\to\filename" /c/windows/gvim.bat `cygpath "$1"` I use this to launch gvim on a file that is specified using a Windows-style backslash path. To learn about the cygpath command, which is used in this script, run one of the following commands at a Git Bash prompt. cygpath --help cygpath --help |less If you pipe the cygpath --help output to the less pager, you need to know how to use less: The essentials are that within less, you can press Space to page down, press b (for back) to page up, and press q to quit. cygpath is analogous to wslpath, which I use in Infinite Ink's qutebrowser Userscripts on Windows. No need to chmod In most Unix-like shells, you need to chmod +x executables but in Git Bash this is not needed. Unicode If you have issues with non-ASCII Unicode characters, run the following at a Git Bash prompt and make sure each setting includes UTF-8. locale Also, you can try to solve Unicode issues by running the following sequence of chcp.com^[12] commands at a Git Bash prompt. chcp.com chcp.com 65001 chcp.com This changes the code page to 65001, which supports UTF-8 encoding. Nowadays UTF-8 is the standard file encoding of the internet (and of Unicode in general). Case insensitivity exceptions --help and other command arguments Arguments to nix-nux commands, in general, are case sensitive. For example, in the following cygpath --help The command cygpath is case insensitive, but its argument --help is case sensitive. For example, this works: Cygpath --help but this does not work: cygpath --Help exit To quit Git Bash, you can either click the close-window X in the upper right corner of the terminal window or type the following at the command prompt: exit This exit command is a system call and must be all lower case. * See also For more related to Git Bash, see Infinite Ink's... * I Use This[?] * qutebrowser Userscripts on Windows * Launching Git Bash in Mintty, ConEmu, VS Code's Terminal, and Other Terminal Emulators * #git-bash Portal * #nix-nux Portal Endnotes --------------------------------------------------------------------- 1. Many Infinite Ink pages, including this one, are evergreen and regularly updated. 2. I have experience using Windows PowerShell (powershell.exe), but do not yet have experience using the cross-platform PowerShell Core (pwsh). To learn about these command-line shells, see wikipedia.org/ wiki/PowerShell. 3. It would probably make more sense if WSL were called LSW (Linux Subsystem for/of/on Windows), but it is not because, according to Rich Turner in this tweet, Microsoft "cannot name something leading with a trademark owned by someone else." Rich's tweet has inspired me to interpret the WSL acronym as meaning Windows' Subsystem for Linux (notice the apostrophe (')). 4. Git Bash uses MSYS2 (Minimal SYStem 2) and MinGW (Minimalist GNU for Windows) to do this emulation. 5. Git Bash is sometimes called "bash on MSYS" or "MSYS bash." 6. In Windows 11, you need to Shift+Right-click on a folder name to see the Git Bash Here command. 7. The more command is not included in Git Bash, but the less command, which can do everything more can do (and more), is included in Git Bash. 8. cat stands for concatenate. 9. grep stands for "get regular expression." Its friends include egrep and fgrep. 10. vim's friends include view, vimdiff, and vimtutor. 11. To list most available commands, run ls /usr/bin and ls /mingw64/ bin. 12. tree.com and chcp.com are located in /c/windows/system32/ and are on your Git-Bash path. Each must be called with the .com file extension. 13. When launching an app from Git Bash, it's sometimes useful to append & to the end of the command so it will be launched as a background job. 14. bash is "Bourne again shell" and sh is "Bourne shell". 15. To learn about some problems with WSL, see Windows Subsystem for Linux: The lost potential by Julio Manuel Merino Vidal. Also see the Hacker News comments about that article at news.ycombinator.com/item? id=25154300. 16. Alternatively, you could use a PowerShell or CMD command-line prompt for this command. Because this article is about Git Bash, I suggest using a Git Bash command-line prompt throughout the article. Note that many of the commands discussed in this article must be run from a Git Bash prompt. --------------------------------------------------------------------- Please share & discuss * Your comment or question via this form might immediately improve this page or help me to (eventually) improve this page. To post or view comments, enable JavaScript. * On Mastodon, I'm @nm@mathstodon.xyz and I'll see your toot if you mention @nm@mathstodon.xyz or #InfiniteInk in it. * You could also [l] Share this page on Mastodon. --------------------------------------------------------------------- Page Meta Git Bash Is My Preferred Windows Shell https://www.ii.com/git-bash-is-my-preferred-windows-shell/ Published 2020-Nov-18 l (c) Nancy McGough l Updated 2024-Jan-19 Made with Asciidoctor & Hugo --------------------------------------------------------------------- More Infinite Ink Pages "Edit This Page" With vscode:// URLs (featuring a Hugo partial) The For-Profit Mozilla Corporation, aka Mozilla DOT COM Connect with Infinite Ink @ Mastodon, GitHub, etc. The Cloud, WebApps, and Desktop Apps qutebrowser Userscripts on Windows Embedding Mastodon Timelines << Hugo and sitemap.txt (& a bit Scoop: A Windows about robots.txt) Package Manager >> Portals: #activism-hacktivism #alpine-mail #asciidoc #backup-sync #browsers #business-economics-money #cheatsheet #cli #elsewhere #emoji #forked #git #git-bash #gohugo #golang #intellij #iusethis #joplin #longform #markdown #mastodon #mathematics #mathjax #messaging #meta #nix-nux #privacy-security #productivity #qutebrowser #tech #tumblelog #twitter #unicode #utf-8 #vim #vscode #webdev #windows #words #zeitgeist --------------------------------------------------------------------- @