KanpurAI
5 min read
Feb 08, 2026

Git Commands Cheat Sheet – Complete Guide to Master Git Basics & Advanced Commands

Samarth Mishra
Author & Contributor
Git Commands Cheat Sheet – Complete Guide to Master Git Basics & Advanced Commands

Introduction

Git is one of the most essential tools in today’s IT industry. Whether you are working in software development, DevOps, or data science, Git plays a crucial role in managing and tracking changes in your project files. Every modern project needs proper version control, and Git is the most popular solution for that purpose.

This Git Commands Cheat Sheet is designed to help beginners as well as working professionals understand Git file management easily. You can use this guide as a quick reference while learning Git and also when you start using it in real-world projects. Even if you are completely new to Git, this cheat sheet will make things simple and practical.


What is Version Control?

Version control, also called source control, is the process of tracking, managing, and maintaining changes made to files over time. It helps teams collaborate efficiently without overwriting each other’s work.

From a technical point of view, version control manages different versions of code, documents, and configurations, ensuring complete history and recovery options.

https://images.openai.com/static-rsc-3/oKK1l5T0sxYKFaMAq8bDSAix7QxlSL4evzSuEV4WT5tfcv5igF8uD7V0JYHhHtssOv_zu7THcCYdzUD7oHcr8vQ7aM7xamA-GEauC_H9Wmk?purpose=fullsize&v=1

Functions of a Version Control System (VCS)

A VCS helps developers to:

  • Work on the same project simultaneously

  • Prevent conflicts and accidental overwrites

  • Maintain a complete change history

  • Roll back to previous versions when required

Types of Version Control Systems

There are two major types:

Centralized VCS (CVCS)Distributed VCS (DVCS)
Uses a single central serverEach developer has a full local repository
Requires constant server connectionMost operations work offline
Slower performanceFaster and more reliable
Server failure can cause data lossLocal copies ensure data safety

Git belongs to the Distributed Version Control System (DVCS) category.


What is Git?

Git is a free and open-source version control tool created by Linus Torvalds in 2005. It helps developers track changes in projects and collaborate efficiently.

Git allows non-linear development, meaning developers can work on multiple features simultaneously using branches. This makes Git extremely powerful for both small and large projects.

According to Stack Overflow surveys, over 90% of developers worldwide use Git as their primary version control tool.


Install Git and GUI Tools

Git is available on Windows, macOS, and Linux. On macOS and Linux, Git is often pre-installed.

Install Git on macOS

  1. Install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install Git:
brew install git

Install Git on Windows

  1. Download Git from:
https://git-scm.com/download/win
  1. Run the installer and follow the setup instructions.

Install Git on Linux

For Ubuntu:

sudo apt-get install git

For other distributions, refer to:

https://git-scm.com/download/linux

Git in DevOps

Git is a core tool in the DevOps lifecycle, especially during the Plan and Code phases.

The DevOps lifecycle includes:

  • Plan

  • Code

  • Build

  • Test

  • Release

  • Deploy

  • Operate

  • Monitor

Git enables Continuous Integration and Continuous Delivery (CI/CD) by allowing teams to collaborate, review code, and manage changes efficiently. It improves code quality, reduces errors, and enhances team productivity.


Key Git Terminologies

Before using Git commands, understanding common terms is important:

  • Local Repository – Project directory on your local machine

  • Remote Repository – Online repository hosted on platforms like GitHub

  • Clone – Copying a remote repository locally

  • Commit – Snapshot of staged changes

  • Branch – Independent line of development

  • Merge – Combining branches

  • Staging Area – Area where changes wait before commit

  • .gitignore – File to exclude unwanted files

  • Stash – Temporary storage of changes

  • Commit Hash – Unique ID for each commit

  • HEAD – Pointer to the latest commit


Branches in Git

Branches allow developers to work on new features without affecting the main codebase.

https://wac-cdn.atlassian.com/dam/jcr%3Ac6db91c1-1343-4d45-8c93-bdba910b9506/02%20Branch-1%20kopiera.png?cdnVersion=3161

  • The main branch contains stable production code

  • Feature branches are created for new development

  • After testing and review, feature branches are merged back into main

This workflow improves collaboration and reduces bugs.


Git Life Cycle

https://www.tutorialspoint.com/git/images/git-lifecycle4.png

The Git lifecycle follows these steps:

  1. Clone repository from remote

  2. Make changes to files

  3. Pull latest updates from remote

  4. Review and stage changes

  5. Commit changes with a message


Features of Git

Git offers several powerful features:

  • Supports multiple developers simultaneously

  • Fast and lightweight

  • Enables non-linear workflows

  • Works offline

  • Highly reliable and secure

  • Open-source and widely supported


Git Commands Cheat Sheet

1. Git Configuration

CommandDescription
git config --global user.name "Name"Set username
git config --global user.email "email"Set email
git config --listView configurations

2. Repository Setup

CommandDescription
git initInitialize repository
git clone URLClone repository

3. Staging & Commit

CommandDescription
git statusCheck file status
git add fileAdd file
git commit -m "msg"Commit changes
git diffView changes

4. Branching & Merging

CommandDescription
git branchList branches
git checkout -b branchCreate & switch branch
git merge branchMerge branch

5. Inspect & Compare

CommandDescription
git logView commit history
git show SHAShow commit details

6. Share & Update

CommandDescription
git pullFetch & merge updates
git push origin branchPush changes

7. Rewrite History

CommandDescription
git rebase branchReapply commits
git reset --hard commitReset history

8. Temporary Commits (Stash)

CommandDescription
git stashSave changes
git stash popRestore changes
git stash clearRemove all stashes

9. Advanced Branch Management Commands

These commands are useful when working with large teams and multiple branches.

CommandDescription
git branch --mergedLists branches already merged into the current branch
git branch --no-mergedShows branches not yet merged
git switch branch-nameSwitch branches (modern alternative to checkout)
git switch -c new-branchCreate and switch to a new branch
git worktree add path branchWork on multiple branches simultaneously

Use case: Helpful when handling hotfixes and parallel feature development.


10. Advanced Commit & History Commands

These commands help you clean, edit, and analyze commit history.

CommandDescription
git commit --fixup <commit>Create a fixup commit for autosquash
git rebase -i HEAD~nInteractive rebase for editing commit history
git cherry-pick <commit>Apply a specific commit to another branch
git blame file-nameShows who changed each line of code
git reflogDisplays reference logs (life saver!)

Pro Tip: git reflog can recover lost commits after mistakes.


11. Advanced Remote Repository Commands

These commands help manage remotes efficiently.

CommandDescription
git remote -vShow all remote URLs
git remote rename old newRename a remote
git fetch --pruneRemove deleted remote branches locally
git push --force-with-leaseSafer force push
git pull --rebasePull changes without merge commits

Always prefer --force-with-lease over --force.


12. Advanced Stash Commands

Stashing becomes powerful with these advanced options.

CommandDescription
git stash push -m "message"Stash with a message
git stash show -pView detailed stash changes
git stash apply stash@{n}Apply a specific stash
git stash branch branch-nameCreate branch from stash

Ideal for quick context switching between tasks.


13. Undo & Recovery Commands (Very Important)

Mistakes happen. These commands save hours of panic.

CommandDescription
git reset --soft HEAD~1Undo commit, keep changes staged
git reset --mixed HEAD~1Undo commit, keep changes unstaged
git revert <commit>Safely undo a commit
git checkout commit -- fileRestore a file from a commit
git restore file-nameRestore file (new syntax)

git revert is preferred for shared branches.


14. Advanced Diff & Debugging Commands

Used to deeply analyze code changes.

CommandDescription
git diff --name-onlyList changed files
git diff --statShow change summary
git diff commit1 commit2Compare commits
git bisect startFind bug using binary search
git bisect good/badMark commits during bisect

git bisect is extremely powerful for debugging production issues.


15. Performance & Cleanup Commands

Keep your repository clean and optimized.

CommandDescription
git gcCleanup unnecessary files
git pruneRemove unreachable objects
git fsckCheck repository integrity
git count-objects -vHRepository size analysis

How Do Git Commands Work?

Git commands move files through Working Directory → Staging Area → Repository. Each command plays a role in tracking, saving, and sharing changes efficiently.


Conclusion

This Git Commands Cheat Sheet is designed to boost your productivity and confidence while working with Git. You don’t need to memorize every command—just bookmark this guide and use it whenever required.

With regular practice, Git will become second nature to you.
Happy coding and best of luck!