Install Git on your PC and Learn Git Bash Commands with Examples

Download and Install Git Bash on Your System

Download and install git bash on your local machine or on a remote desktop server. You can download git from this official link 👉 Download GitDownload only the latest development version of git.

Next Steps after Installing the Git Bash

Checking the version of Git

You can run the git --version command to check the current installed version of git on your local machine. 

Example: git --version

Configure Git global Username and Email

After installing the git, you should configure global username and email inorder to perform the git operations on bash. use the command git config --global user.name "mention name here" to set up your Global Username. 

Example: git config --global user.name "CloudTechIN"

Use the command git config --global user.email "<your_github_email>@<domain>.com" to set up your Global Email.

Example: git config --global user.email "cloudtechin@cloudtechinblog.com"

Once you are done with Global configuration then you are ready to start working on Git.

Now Start Learning Git Commands with Examples

How to initialize Git on the current folder?

Run the command git init to initialize git and to create a new directory.

Example: git init AzureDevOps-Repo

How to set the user name for the current repository in Git?

Run the command git config user.name "mention name here"

Example: git config user.name "CloudTechIN"

How to check the Status of the Git?

Run the command git status to check the status of the Git

How to check the compact version of the status for a repository in Git?

Run the command git status --short to check the compact version of the status for repository

How to stage all new, modified, and deleted files in Git?

Run the command git add -A to stage all new, modified, and deleted files.

How to commit the changes to the current repository with the message in Git?

Run the command git commit -m "add some message text here" to commit the changes to the current repository with the message

How to commit the updated files directly, skipping the staging environment in Git?

Run the command git commit -a -m "add some message text here" to commit the updated files directly, skipping the staging environment

How to view the history of commits for the repository in Git?

Run the command git log to view the history of commits for the repository

How to list the existing branches in Git?

Run the command git branch to list the existing branches in repo.

How to create a new branch in Git?

Run the command git branch "name of the branch" to create a new branch in repo.

How to switch or move to a new branch in Git?

Run the command git checkout "name of the branch" to switch or move to a new branch in repo.

How to directly create and move to a new branch in Git?

Run the command git checkout -b "name of the branch" to directly create and move to a new branch in repo.

What are the Advantages of using Git?

Git has various advantages for developers to review project history and to track the following changes like

  • Which changes were made?
  • When were the changes made?
  • Who made the changes?
  • Why were changes needed?

Resources: