How to Use Git Bash on Windows
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.
Table of Contents
What is Git Bash?
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.
What can you do with Git Bash on Windows?
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.
How to download and install Git Bash
You can download and install the app by following these simple steps.
- Download Git-2.31.0-64-bit.exe from the Git website.
- Double click the downloaded executable.
- In the dialog box, click Yes.
- Click Next again and select the default settings until you see the Git 2.31 Setup wizard screen, as shown below.
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.
How to use Git Bash on Windows
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.
Using Unix commands
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.
Popular Git commands
Git Bash is used for running Git commands, so let’s get familiar with some of the most important ones.
- Open the app.
- Next, run the git init command to initialize your new repository, as shown below.
- Next, create a file inside the same directory using the echo command. This command will create the file and add data into it.
echo "My first change" > adding-new-file.txt
- Now, check the status of the Git repository using the git status command.
- Now add the file to the Git repository using the git add command below.
- Again check the status of the git repository, and you should see the file has been added to the local repository.
- To commit your changes in the Git repository, run the git commit command below.
git commit -m "MY FIRST COMMIT"
Using Git commands in the Command Prompt
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 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?
More in DevOps
What is Datadog – The Ultimate Guide
May 12, 2022 | Sagar
How to Use Git Bash on Windows
Apr 25, 2022 | Sagar
What is Ansible – The Ultimate Guide
Apr 7, 2022 | Sagar
What is Grafana: The Ultimate Guide
Mar 30, 2022 | Sagar
How to Check out a Remote Git Branch
Mar 18, 2022 | Sagar
Disaster Recovery for Kubernetes
Jan 24, 2022 | Michael Otey
Most popular on petri