If you’re looking for the most practical and complete Git Cheat Sheet for 2025, you’ve landed in the right place. Git is the most widely used version control system, trusted by developers, teams, and companies around the world to manage source code and collaborate efficiently. This Git quick reference guide by Solviyo is designed to be your one-stop resource — whether you’re a beginner just learning Git basics or an experienced developer working on large projects.
In this cheat sheet, you’ll find all the essential Git commands with examples, organized into clear sections like repository setup, branching, merging, stashing, undoing mistakes, and working with remote repositories such as GitHub, GitLab, and Bitbucket. Each command is explained in plain language, so you’ll not only know what to type but also why and when to use it.
We’ve included both beginner-friendly Git commands (like git init
, git add
, git commit
) and advanced Git tips (like git rebase
, git cherry-pick
, and Git aliases) to save you time and boost your productivity. You’ll also learn common workflows for solo projects and team collaboration, plus quick fixes for errors like merge conflicts or accidental commits.
Whether you’re preparing for a coding interview, managing open-source contributions, or just need a Git commands list for daily reference, this page is structured to make your workflow smoother. For convenience, you can also download the Git cheat sheet PDF version and keep it handy on your desktop or mobile. Bookmark this guide now — it’s your ultimate Git quick reference for 2025.
⏳ Generating your PDF, please wait...
Quick Setup & Configuration
Before using Git, configure your identity and preferences. These commands help set up your name, email, and default settings:
Command | Description |
---|---|
git config --global user.name "Your Name" |
Set your Git username (used in commits). |
git config --global user.email "you@example.com" |
Set your Git email address (linked with commits). |
git config --list |
Check all Git configuration settings. |
git config --global core.editor "code --wait" |
Set default code editor (example: VS Code). |
git config --global init.defaultBranch main |
Set default branch name to main instead of master . |
--global
for system-wide settings, or omit it to configure Git per repository.Repository Basics
A Git repository (repo) is where your project’s history is stored. Use these commands to create, clone, and explore repositories:
Command | Description |
---|---|
git init |
Create a new local repository in the current directory. |
git clone |
Clone an existing remote repository (GitHub, GitLab, etc.) to your machine. |
git status |
Check the current status of your working directory (changes, staging, branch). |
git log |
View commit history of the repository. |
git log --oneline --graph --decorate |
View a simplified, graphical commit history. |
git init
, always create a README.md
and make the first commit to establish a clean starting point.Branching & Merging
Branches let you work on features, fixes, or experiments in isolation. Merging integrates changes from one branch into another.
Command | Description |
---|---|
git branch |
List all local branches. |
git branch |
Create a new branch. |
git checkout |
Switch to an existing branch. |
git checkout -b |
Create and switch to a new branch in one step. |
git merge |
Merge the specified branch into the current branch. |
git branch -d |
Delete a branch safely (only if it’s been merged). |
git branch -D |
Force delete a branch (even if not merged). |
main
(or develop
) via pull requests to keep history clean.Working with Remote Repositories
Remotes are versions of your project hosted online (GitHub, GitLab, Bitbucket). These commands help you connect, fetch, and sync changes.
Command | Description |
---|---|
git remote -v |
Show all remotes linked to the repository. |
git remote add origin |
Add a new remote repository (commonly named origin ). |
git push -u origin main |
Push commits to the remote repository and set upstream branch. |
git fetch origin |
Download objects and refs from the remote (does not merge). |
git pull |
Fetch and merge changes from the remote into the current branch. |
git push |
Push local commits to the remote repository. |
git remote remove origin |
Remove a remote connection. |
git pull
before pushing to avoid conflicts. Use git fetch
if you just want to see changes without merging.Undo & Fix Mistakes
Everyone makes mistakes while coding. Git provides multiple ways to undo changes depending on whether they are staged, committed, or pushed.
Command | Description |
---|---|
git restore |
Discard changes in the working directory (restore file from last commit). |
git restore --staged |
Unstage a file (move it back from staging area to working directory). |
git reset HEAD~1 |
Undo the last commit but keep the changes staged. |
git reset --hard HEAD~1 |
Completely remove the last commit and its changes (⚠ irreversible). |
git commit --amend |
Edit the last commit (message or staged changes). |
git revert |
Create a new commit that reverses the changes of a previous commit (safe for shared repos). |
git revert
for public branches (shared repos) and git reset
only for local changes that aren’t pushed yet.Stash & Save Work
Git stash lets you temporarily save uncommitted changes without committing them. It’s handy when you need to switch branches or pull updates quickly.
Command | Description |
---|---|
git stash |
Save uncommitted changes and clean working directory. |
git stash save "message" |
Save changes with a custom message for clarity. |
git stash list |
View the list of stashed changes. |
git stash apply |
Apply the most recent stash (keeps it in stash list). |
git stash pop |
Apply the most recent stash and remove it from stash list. |
git stash drop stash@{n} |
Remove a specific stash entry. |
git stash clear |
Remove all stashed entries. |
git stash apply
if you want to reuse the same stash multiple times. Use git stash pop
if you want it removed after applying.Advanced & Productivity
Once you’re comfortable with Git basics, these advanced commands and productivity tricks can help streamline your workflow and solve tricky problems.
Command | Description |
---|---|
git rebase |
Reapply commits on top of another base branch (cleaner history). |
git rebase -i HEAD~n |
Interactive rebase to squash, reorder, or edit commits. |
git cherry-pick |
Apply a specific commit from another branch to the current branch. |
git bisect |
Binary search to find the commit that introduced a bug. |
git blame |
Show who last modified each line of a file (great for debugging). |
git shortlog -sn |
See contribution summary by author (useful for stats). |
git alias |
Create shortcuts for frequently used Git commands. |
git config --global alias.co checkout |
Example: create alias git co for git checkout . |
rebase
for a clean commit history, cherry-pick
for selective fixes, and aliases
to save time on repetitive commands.Common Git Workflows
Git is flexible and can adapt to many different workflows. Choosing the right workflow depends on whether you’re working alone or as part of a team. Below are the most common and practical Git workflows every developer should know.
Workflow | Steps & Description |
---|---|
Solo Developer Workflow |
Ideal for personal projects or small scripts where you’re the only contributor. The basic cycle is:
You initialize a repo, add files, commit changes, and push them to a remote service (like GitHub) for backup or deployment. |
Team Collaboration Workflow |
Commonly used in professional teams. Developers clone the repository, create feature branches, and submit changes via pull requests (PRs). The cycle looks like this:
This keeps the |
Feature Branch Workflow |
A variation of team workflow where every new feature or bug fix is developed on a dedicated branch:
This workflow makes tracking features easier and avoids cluttering the main branch with incomplete code. |