Git Bash is a terminal emulator shell and limited Linux-like environment for Windows that lets you run Git commands. Learn how to use the app in this detailed guide.
Git Bash is a software tool for Windows. It runs Git commands using an emulation layer. Bash is a command-line shell for Nix operating systems. Git Bash installs Bash, some bash utilities, and Git on Windows.
The app also lets you connect to remote Git repositories such as GitLab or GitHub, and run hundreds of Git commands like git clone, git config, etc. Although the app allows you to run all Git-related commands, it’s also a Linux terminal that can run any standard Unix commands.
Now that you have a basic idea of what Git Bash is, it’s also important to understand everything you can do with it.
The app allows you to execute Linux commands, and run shell scripts, and it also allows you to navigate to text files and directories using the ls (list files) or cd (change directory) commands, or edit files using the vim command.
For example: cd /usr/bin changes the working directory to the bin directory.
The app also allows you to connect to Git repositories and manage them.
You can download and install the app by following these simple steps.
Next, select the location on your system where you would like to store the Git installation files.
Now, tick the checkbox Additional icons -> On the desktop to make it easier to access the app in the future. Also, you can set up the integration with the File Explorer here.
Next, on the Adjusting your PATH environment screen, select the Git from the command line and also from 3rd party software option.
Next, when you need to choose the SSH executable, select OpenSSH. This will allow you to work with Secure Shell (SSH) connections, like when you log into a Linux machine.
Finally, select Use MinTTy, select the default terminal MSYS2, which the app will use as a terminal emulator. After clicking Next, the app will start.
Now let’s open Git Bash and use it. First, navigate to the path where you installed app and click on the .exe file. You can also search for the app in the Windows Start menu.
By default, the background color of the app is black, but if you wish to change any configuration settings, you can do it anytime by right-clicking on the toolbar at the top of the terminal window and navigating to the Options screen.
After you navigate to Options, you will see a lot of configuration settings that you can change according to your preferences.
As you can see below, we’ve changed the text size and the background color has turned to dark blue.
If you want to execute a shell script on Windows or any Unix command, then you can run them in the app as it works like the Windows command-line shell. Let’s execute some Unix commands as shown below.
As you can see below, I created a folder using the Unix command mkdir and later verified it using the ls and grep commands.
mkdir Folder ls Folder | grep Folder
Similarly, if you run the echo command, it prints the output in the terminal, as shown below.
echo "Hello"
Git Bash is used for running Git commands, so let’s get familiar with some of the most important ones.
git init
echo "My first change" > adding-new-file.txt
git status
git add
git status
git commit -m "MY FIRST COMMIT"
Did you know that running Git commands is possible in the Windows command prompt as well? The command prompt allows you to execute any Git command such as git init, git commit, etc. This will still require you to install Git Bash for Windows.
As you can see below, the git status command has been executed in the command prompt successfully.
Git Bash is a free tool with a whole lot of features. With this guide, you learned how to install and use the app on Windows. Also, you learned how to connect to a Git repository and manage it with various other commands.
Now that you have a good idea of what the app can do, which commands do you plan to execute with it?
Related Article: