If you are a web developer but work mainly on Windows environments like me, you may have known about Git Bash. It’s based on MinGW64 (Minimalist GNU for Windows x64). It serves well for its purpose but sometimes it’s kind of boring. Due to the need to maintain backward compatibility, newer features of Bash are rarely enabled by default. WSL is a good replacement but it needs configurations on the system level. Not very handy if you work in a limited access system. So back to Git Bash, no worries, we can tweak it a little bit to enhance the experience. In this tutorial, I will assume that you installed Git for Windows and (optionally) Windows Terminal.
Bash uses a few startup files to configure the shell environment for users. It will source files like ~/.bash_profile, ~/.bash_login, and ~/.profile in the order given. The first readable file that exists is sourced.
Create ~/.bash_profile file. The .bash_profile contains commands for setting the shell’s environment variables. Since the shell is interactive, the ~/.bashrc file is not sourced. Copy the following content to the file:
Create ~/.bashrc file. The .bashrc file contains commands that are specific to the Bash shell. It is the best place for aliases and bash-related functions. Copy the following content to the file:
The Git Bash prompt is set by a shell script called git-prompt.sh and can be found in the c/Program\ Files/Git/etc/profile.d directory. Notice that in lines 8-10, a custom ~/.config/git/git-prompt.sh file will be sourced, if it exists. This is our chance to override the default settings.
So let’s create ~/.config/git/git-prompt.sh file. The git-prompt.sh file contains commands for setting the title of the Git Bash terminal and the Bash prompt string. This is where you decide how your prompt will look like. Here is an example setting:
Create ~/.inputrc file, where you will able to configure command history, directory display, and keyboard bindings using the built-in GNU Readline library.
Here are some shortcuts provided by the Readline library:
Some Bash utilities are also included with Git for Windows and may be used to enhance your Git experience if the default behavior is not desired. These utilities will need to be configured in each independent development environment. Check out the Pro Git Book for more information.
The git-completion and git-prompt scripts can be found in the following directory: /c/Program\ Files/Git/mingw64/share/git/completion/. Copy the git-completion.bash and git-prompt.sh to your home directory.
To use the scripts append the following lines to the ~/.bashrc file.