Git Commands Cheat Sheet 2026: Every Command You Need to Know
Published March 28, 2026 · COD-AI.com Team
Git Cheat Sheet: Your Comprehensive Guide
Git is an essential tool for version control that allows developers to track changes in code, collaborate with others, and manage projects smoothly. In this comprehensive cheat sheet, we will categorize commands and examples to help you navigate Git effectively.
Setup & Config
Before you start using Git, you need to set it up with your personal information and configure it according to your needs.
Installing Git
To install Git, you can download it from the official website or use a package manager:
- Windows: Download from git-scm.com
- macOS: Use Homebrew:
brew install git - Linux: Use your package manager, for example:
sudo apt-get install git
Configuring Git
Set your username and email to manage commits properly:
git config --global user.name "Your Name"git config --global user.email "[email protected]"
You can verify your configuration with:
git config --list
Creating Repos
Creating a repository is the first step in using Git for version control.
Initializing a New Repository
To create a new local repository, navigate to your project directory and run:
git init
Cloning an Existing Repository
If you want to work on an existing project, you can clone it using:
git clone
Replace <repository-url> with the URL of the repository, such as:
git clone https://github.com/username/repo.git
Basic Snapshotting
Git allows you to take snapshots of your code at any point in time.
Adding Changes
Once you have modified files, you need to add them to the staging area:
git add
You can also add all changes by using:
git add .
Committing Changes
After staging your changes, you can commit them with a message:
git commit -m "Your commit message"
Branching & Merging
Branches are used to develop features without affecting the main codebase.
Creating a Branch
git branch
To create and switch to a new branch in a single command:
git checkout -b
Switching Branches
git checkout
Merging Branches
To merge changes from one branch into another, first switch to the branch you want to merge into, and then run:
git merge
Sharing & Updating
Once you have made your changes, you need to share them with others or update your local repository.
Pushing Changes
Send your commits to a remote repository using:
git push origin
Pulling Changes
To update your local repository with changes from the remote repository, use:
git pull origin
Inspection & Comparison
Git provides commands to inspect and compare changes in your repository.
Viewing Status
Check the status of your changes with:
git status
Viewing Commit History
To view your commit history, you can use:
git log
Comparing Changes
To compare changes between commits, branches, or your working directory, use:
git diff
Undoing Changes
Git allows you to undo changes efficiently.
Unstaging Files
To remove a file from the staging area, use:
git reset
Reverting Commits
To undo a commit and create a new commit that undoes the changes:
git revert
Resetting to a Previous Commit
To reset your repository to a previous state (be cautious with this):
git reset --hard
Advanced Features
For more advanced Git operations, consider the following commands:
Rebasing
Rebasing is used to integrate changes from one branch into another without creating a merge commit:
git rebase
Cherry-Picking
To apply a commit from one branch onto another, you can cherry-pick:
git cherry-pick
Stashing Changes
If you want to save your changes temporarily without committing, you can stash them:
git stash
To view your stashed changes:
git stash list
To apply the stashed changes back to your working directory:
git stash apply
Common Workflows
Feature Branch Workflow
This workflow is great for developing new features in isolation:
- Start from the main branch:
git checkout main - Create a new feature branch:
git checkout -b feature-branch - Make changes and commit them:
git commit -m "Feature implemented" - Switch back to main:
git checkout main - Merge the feature branch:
git merge feature-branch - Delete the feature branch after merging:
git branch -d feature-branch
Collaborative Workflow
In a team environment, follow this workflow:
- Create a personal fork of the repository.
- Clone your fork locally:
git clone - Set up the original repository as a remote:
git remote add upstream - Regularly pull changes from the upstream:
git pull upstream main - Collaborate on features using branches.
- Push changes to your fork:
git push origin - Create a pull request to the original repository.
Conclusion
This Git cheat sheet provides a thorough overview of essential commands and workflows that can be used in everyday development. Familiarizing yourself with these commands will help you manage your projects more effectively, whether you are working alone or as part of a team.
Git is a powerful tool, and mastering its commands will greatly improve your version control experience. Happy coding!
🛠️ Try Our Free Tools