Git is one of the most popular version control tools among software developers, and professional developers used Git commands regularly in their projects. On top of that, most of the software companies used Git to manage the project versions and set up CI/CD pipelines for automatic project deployment. So, if you are planning to join a software development team where more than one developer works on a project simultaneously, then it is essential to understand the Git version control system.
This blog post provides a quick setup process for Git and a few useful commands. We will start this tutorial by explaining how to set up up the Git application. After that, we will check the git version and set up the user name and user email for the git account. Next, we will learn how to initialize a git repository for a project, check the git status, and set up a git remote repository for the project. Then, we will learn git push and pull commands and create new branches. Finally, we will understand the git log commands.
Git application setup
- Download the Git application from https://git-scm.com
- Install it on your computer.
- Open the terminal (Mac) or PowerShell (Windows).
- Once done, run the following command to check the git version.
git --version
Or
git --v
Output

Set up a Git user name and email.
git config --global user.name "Your Name" git config --global user.email "Your Email"
Validate Git user information
git config --global user.name git config --global user.email
Git initialization command
Go to a project directory and run the following command to initialize a git repository.
git init
Check Git repository status
git status
Git add and commit command
git add -A git commit -m "your_custom_commit_message_in_here"
You can also combine those two lines of commands into a single line.
git commit -am "your custom_commit_message_in_here"
Set up the origin of the remote repository.
git remote add origin "git_remote_repository_url"
Check remote origin status
git remote -v
Set the default upstream branch for push and pull.
git push -u origin main
Git pull and push command
git push origin main git pull origin main
Set a new URL for remote origin.
git remote set-url origin "git_remote_repository_url"
Git Branch Commands
// List of all branches. git branch -a // Create a new branch and switch to that branch git checkout -b "new_branch_name" //Rename current branch. git branch -m "new_renamed_branch_name" // delete a branch. git branch -d "deleted_branch_name" //switch to a branch. git checkout "branch_name" // merge a branch. git merge "branch_name"
git logs in oneline mode
git log --oneline
Output

git logs in graphical mode
git log --graph
Output

Last 3 git logs
git log -3

Blog credit: https://github.com/xenioushk/useful-git-commands