Introduction
Git is a version control system that lets developers track source code changes during software development. Git Bash is an application for Microsoft Windows, allowing developers to use Git in a command-line interface.In this article, you will learn what Git Bash is and how to use it.
Prerequisites
- A system running Windows
- A network connection
What Is Git Bash
Git Bash is a Microsoft Windows application with a Git command-line shell experience and utilities, such as Secure Shell Protocol (SSH), Secure Copy Protocol (SCP), CAT (concatenate command), etc. Bash is an acronym for Bourne Again Shell, which is a GNU Project shell.A shell is used to interface with an operating system by executing commands, and Bash is the default shell used on Linux and macOS.Note: For a detailed overview of basic Git functionalities, read our Beginner's guide for using Git.
What Is Git Bash Used For
Git Bash emulates a bash environment on Windows, allowing users to use the Bash shell and most of the standard Unix commands on a Windows OS. Users can interact with a repository and Git elements by running commands in Git Bash.How to Install and Set Up Git Bash (A Step-by-Step Guide)
Follow the steps below to install and set up Git Bash.Step 1: Download and Install Git Bash
First, you must install Git on your machine. Follow the steps outlined in the tutorial to download and install Git on Windows systems.Step 2: Launch Git Bash
After installing Git, search for Git Bash in the start menu. Press Enter to launch the app.

Step 3: Connect to a Repository
The syntax to configure your local Git installation to use your GitHub credentials is:git config --global user.name "github_username"
git config --global user.email "email_address"
Replace github_username
and email_address
with your GitHub credentials.
git clone [repository_url]
Find your repository_url
in the Code section of your GitHub page:
clone
command:
How to Use Git Bash
The following section explains the basic functionalities of Git Bash and the available commands.- Initialize
git init
command creates an empty .git repository or reinitializes an existing one.Note: Running
git init
when you already have an existing repository doesn't overwrite your existing files but adds new templates.
- Navigate
cd
command allows you to change the directory in which Git Bash operates. The syntax is:cd [directory-name]
For example:
ls
For example:
- Status
git status
command lists all the modified files ready to be added to the local repository.
git status
command shows the modified and new files that haven't been added to the index and that Git doesn't track yet. While Git is aware of the files, you have to let Git know you want to track changes to these files.- Add
git add
command updates the index with the content in the working tree and prepares the content in the staging area for commit.You can add both files and directories to the index. The syntax is:git add [directory] | [file]
For example:
git add -A
command to add all the files from the directory that haven't been added to the index yet.- Commit
git commit
command. The git commit
command instructs Git to store that file version. Git only commits the changes made in the repository.The syntax is:git commit -m "Commit notes"
For example:
- Pull
git pull
command fetches changes from a remote repository to your local repository.Before running the git pull
command, make sure that your central repo is set as origin. Run:git remote add origin [your-repository-link]
After setting your origin repository, run:git pull origin master
For example:
- Push
git push
command is the opposite of the git pull
command. This command sends files from the local repository to the remote repository.Run the following command:git push origin master
For example:
- Branch
git branch [branch-name]
For example:
git checkout [branch]
Replace [branch]
with the branch name you want to switch to.For example:
- Merge
git merge
command allows you to merge two branches together.Important: Ensure you are on the target (merge-receiving) branch when running the
git merge
command. Switch to the target branch using git checkout
.git merge [branch-name]
For example: