TL;DR
- `git status`, `git add`, `git commit`, `git pull`, and `git push` cover most everyday Git workflows.
- Use `git branch`, `git switch`, and `git merge` to manage branches and combine development work.
- Use `git fetch` when you want to retrieve remote changes without immediately integrating them into your current branch.
- Use `git restore`, `git revert`, and `git reset` for different types of undo operations.
- `git reflog` can help recover commits after accidental resets, rebases, or deleted branches.
- `git bisect` helps identify the commit that introduced a bug.
- `git worktree` is useful when you need to work on multiple branches at the same time.
- Advanced commands such as `git rebase -i`, `git cherry-pick`, `git commit –fixup`, and `git push –force-with-lease` provide greater control over Git history and collaboration.
- Git Bash combines standard Git commands with Bash commands such as `cd`, `ls`, `pwd`, and `mkdir`.
- You do not need to memorize every command. Use this Git command cheat sheet as a practical reference when you need it.
Git is one of the most widely used version control systems in modern software development. Developers use it to track code changes, collaborate with teams, manage multiple development branches, review project history, and recover from mistakes.
Most developers quickly learn commands such as `git add`, `git commit`, `git pull`, and `git push`. However, Git provides many additional commands that become increasingly valuable when projects grow more complex.
This Git commands cheat sheet covers basic Git commands, common Git commands, Git Bash commands, branch management, remote repositories, undo operations, debugging, recovery, and advanced workflows.
Whether you are just starting with Git or already working on production software, this guide can serve as a practical reference for daily development.
Quick Git Commands Cheat Sheet
| Command | Purpose |
| git –version | Check the installed Git version |
| git config | Configure Git settings |
| git init | Initialize a new Git repository |
| git clone <url> | Clone an existing repository |
| git status | Check repository status |
| git add <file> | Stage a specific file |
| git add . | Stage changes in the current directory |
| git commit -m “message” | Create a commit |
| git diff | View unstaged changes |
| git log | View commit history |
| git branch | List or create branches |
| git switch <branch> | Switch branches |
| git merge <branch> | Merge another branch |
| git fetch | Download remote changes |
| git pull | Fetch and integrate remote changes |
| git push | Push local commits |
| git stash | Temporarily save local changes |
| git restore <file> | Restore file changes |
| git revert <commit> | Reverse a commit with a new commit |
| git reset | Move HEAD or reset repository state |
| git reflog | View previous HEAD positions |
| git cherry-pick <sha> | Apply a specific commit |
| git rebase | Replay commits on another base |
| git bisect | Find the commit that introduced a problem |
| git worktree | Work on multiple branches simultaneously |
Basic Git Commands Cheat Sheet
These commands cover the core workflow developers use when creating repositories, tracking files, and saving changes.
1. Check Your Git Version
git –version
This command confirms whether Git is installed and displays the currently installed version.
2. Configure Your Git Username
git config –global user.name “Your Name”
Git associates this name with the commits you create.
3. Configure Your Git Email
git config –global user.email “you@example.com”
git config –global –list
Your email is also stored with your commits.
Use the second command to review your global configuration.
4. Initialize a Git Repository
git init
`git init` creates a new Git repository inside the current directory.
Use it when starting version control for an existing local project.
5. Clone an Existing Repository
git clone <repository-url>
git clone https://github.com/user/project.git
Cloning downloads the project files and Git history so you can begin working with the repository locally.
6. Check Repository Status
git status
This is one of the most useful commands in any basic Git commands cheat sheet.
It shows:
- Current branch
- Modified files
- Staged changes
- Untracked files
- Branch synchronization status
Running `git status` frequently helps you understand exactly what Git sees before you stage, commit, reset, or switch branches.
7. Stage a File
git add app.js
This stages one specific file for the next commit.
8. Stage Multiple Changes
git add .
git add -p
The first command stages changes in the current directory and its subdirectories.
Use `git add -p` when you want more control over exactly which changes are staged.
9. Commit Changes
git commit -m “Add user authentication”
A commit creates a recorded snapshot of the staged changes.
Good commit messages should explain what changed clearly.
Instead of `Update`, use something more descriptive such as `Add password reset validation`.
10. View Unstaged Changes
git diff
git diff –staged
The first command shows changes in your working directory that have not yet been staged.
The second command shows staged changes.
11. View Commit History
git log
git log –oneline
git log –oneline –graph –decorate –all
Use the compact and graph variants when you want a faster overview of repository history and branch relationships.
Common Git Commands Cheat Sheet for Daily Development
After the basic workflow, developers spend much of their time working with branches, remote repositories, merges, and synchronization.
Git Branch Commands
Create a New Branch
git branch feature-login
This creates a branch without switching to it.
Create and Switch to a New Branch
git switch -c feature-login
This creates the branch and immediately switches to it.
List Branches
git branch
Switch to Another Branch
git switch main
git checkout main
git checkout is still widely used, but git switch provides a clearer command specifically for changing branches.
Delete a Local Branch
git branch -d feature-login
git branch -D feature-login
Use the capital `-D` option carefully when you need to force deletion.
Merge a Branch
git switch main
git merge feature-login
First move to the branch that should receive the changes, then merge the feature branch.
Git Remote Commands
Remote commands allow developers to collaborate using platforms such as GitHub, GitLab, and Bitbucket.
View Remote Repositories
git remote -v
Add a Remote Repository
git remote add origin <repository-url>
Fetch Remote Changes
git fetch
`git fetch` retrieves remote updates without automatically integrating them into your current branch. It is useful when you want to inspect incoming changes before merging or rebasing.
Pull Remote Changes
git pull
`git pull` retrieves remote changes and integrates them into the current branch according to the configured Git behavior.
Push Local Commits
git push
git push -u origin feature-login
When pushing a new branch for the first time, `-u` sets the upstream branch, making future pushes and pulls simpler.
Git Bash Commands Cheat Sheet
Git Bash provides Windows users with a Bash-style terminal where they can run Git commands and common shell commands.
Git commands usually begin with `git`.
git status
git add .
git commit -m “Update dashboard”
git push
Git Bash also supports common shell commands.
| Git Bash Command | Purpose |
| pwd | Display the current directory |
| ls | List files and directories |
| cd folder | Move into a directory |
| cd .. | Move to the parent directory |
| mkdir project | Create a new directory |
| touch file.txt | Create an empty file |
| clear | Clear the terminal |
| rm file.txt | Remove a file |
A useful Git Bash commands cheat sheet therefore includes both Git operations and navigation commands.
Git Stash Commands
Git stash temporarily stores unfinished changes so you can switch context without creating an incomplete commit.
Stash Current Changes
git stash
View Saved Stashes
git stash list
Restore the Latest Stash
git stash pop
Create a Named Stash
git stash push -m “WIP login form”
Review Changes Inside a Stash
git stash show -p
Stash Selected Changes
git stash push -p
Advanced stash workflows are particularly useful when developers need to temporarily change context while keeping unfinished work separate.
How to Undo Changes in Git
Different Git commands should be used depending on whether your changes are unstaged, staged, committed, or already pushed.
Restore Changes in a File
git restore app.js
This can discard local modifications to the specified file. Use it carefully because those working-directory changes may be lost.
Unstage a File
git restore –staged app.js
This removes the file from the staging area while preserving the changes in your working directory.
Amend the Previous Commit
git commit –amend
Use this when you need to update the most recent commit message or include additional staged changes. Be careful when amending commits already shared with other developers because changing a commit creates a different commit history.
Undo the Previous Local Commit but Keep Changes Staged
git reset –soft HEAD~1
The commit is removed, but the changes remain staged.
Undo the Commit and Unstage the Changes
git reset HEAD~1
The changes remain in your working directory.
Remove the Previous Commit and Changes
git reset –hard HEAD~1
This is a destructive command. Make sure you understand the current repository state before using it.
Undo a Commit That Has Already Been Pushed
git revert <commit-sha>
‘git revert’ creates another commit that reverses the changes introduced by an earlier commit. For shared branches, this is usually safer than rewriting existing commit history.
Advanced Git Commands Every Developer Should Know
Git becomes especially powerful when you need to recover work, debug regressions, maintain clean history, or handle several development streams at once.
The advanced workflow focuses on commands such as `reflog`, `bisect`, `worktree`, interactive rebase, fixup, and safer force pushing.
1. Recover Lost Commits with Git Reflog
git reflog
`git reflog` records changes to local references such as HEAD.
Imagine accidentally running:
git reset –hard HEAD~1
Your latest commit may appear to have disappeared. Run:
git reflog
Find the previous HEAD position and restore it if appropriate:
git reset –hard HEAD@{1}
Reflog can be extremely useful after:
- Accidental resets
- Deleted branches
- Failed rebases
- Incorrect checkouts
- Lost local commits
2. Find Bugs Faster with Git Bisect
When a regression appears somewhere across hundreds of commits, manually reviewing every commit can take significant time. git bisect helps narrow down the commit that introduced the problem.
git bisect
Start the process:
git bisect start
git bisect bad
git bisect good <known-good-commit>
Git then checks out a commit between the good and bad versions. After testing it, mark it:
git bisect good
git bisect bad
Git repeatedly narrows the range until it identifies the commit that introduced the problem.
You can also automate the process with a test script:
git bisect run ./test.sh
3. Apply a Specific Commit with Git Cherry-Pick
Sometimes you need one change from another branch without merging everything on that branch.
git cherry-pick <commit-sha>
For example, suppose a critical fix exists in a development branch, but several unfinished features are also present. Instead of merging the entire branch, cherry-pick only the fix commit.
This is particularly useful for:
- Production hotfixes
- Backporting bug fixes
- Moving isolated changes between branches
- Applying a specific feature commit
4. Work on Multiple Branches with Git Worktree
Instead of repeatedly stashing and switching branches, Git worktree allows multiple working directories connected to the same repository.
git worktree add ../hotfix hotfix
git worktree list
git worktree remove ../hotfix
For example, you might continue a large refactor in your main directory while fixing an urgent production problem in another worktree.
5. Clean Commit History with Interactive Rebase
During development, a feature branch might accumulate commits such as:
WIP
Fix typo
Fix again
Update validation
Actually fix validation
Before merging, you may want to clean this history.
git rebase -i HEAD~5
Interactive rebase allows you to:
- Reorder commits
- Reword commit messages
- Squash commits
- Fix up commits
- Edit commits
- Drop unnecessary commits
The result can be a smaller, cleaner set of logical commits that is easier for reviewers and future developers to understand.
Avoid rebasing shared branches unless your team understands and coordinates the history rewrite.
6. Use Git Fixup and Autosquash
Suppose you already created a commit and later discover a small correction. Instead of manually reorganizing the history, create a fixup commit:
git commit –fixup <commit-sha>
Then run:
git rebase -i –autosquash <base>
Git automatically places the fixup commit next to the commit it corrects. This is useful when preparing feature branches for pull requests.
7. Push Rewritten History More Safely
Sometimes you intentionally rebase or amend your own remote feature branch. A normal push may be rejected because the history has changed.
Avoid immediately using:
git push –force
A safer option is:
git push –force-with-lease
`–force-with-lease` provides additional protection against accidentally overwriting remote changes that you did not expect. It should still be used carefully and generally only on branches where history rewriting is appropriate.
More Useful Git Cheat Sheet Commands
See Who Changed a Line
git blame app.js
git blame -L 20,40 app.js
This can help identify the commit and developer associated with particular lines.
Inspect a Commit
git show <commit-sha>
This displays commit information and associated changes.
Create a Git Tag
git tag v1.0.0
git push origin –tags
Tags are commonly used to identify software releases.
Rename or Move a File
git mv old-name.js new-name.js
Remove a Tracked File
git rm old-file.js
Preview Untracked Files Before Cleaning
git clean -n
git clean -fd
Use `git clean` carefully because removed untracked files may not be recoverable through normal Git history.
Common Git Workflows
Starting a New Git Repository
git init
git add .
git commit -m “Initial commit”
git remote add origin <repository-url>
git push -u origin main
Starting a New Feature
git switch main
git pull
git switch -c feature/dashboard
git add .
git commit -m “Build dashboard”
git push -u origin feature/dashboard
Updating a Feature Branch
git fetch origin
git rebase origin/main
Your team may alternatively prefer a merge-based workflow.
Undoing a Pushed Commit
git revert <commit-sha>
git push
Recovering a Lost Commit
git reflog
Find the required commit or previous HEAD state and restore it using the appropriate branch or reset operation.
Git Merge vs Git Rebase
Git merge and Git rebase both combine development histories, but they work differently.
Git Merge
git merge feature
Merge combines branches while preserving their existing histories. It can create a merge commit showing where the histories came together.
Git Rebase
git rebase main
Rebase takes your branch commits and replays them on top of another base.
A practical approach is:
- Use merge when preserving shared branch history is important.
- Use rebase to update or clean a local feature branch.
- Avoid rewriting history that other developers are already using.
Git Stash vs Git Worktree
Both commands help when you need to change development context.
Use Git Stash When:
- The interruption is temporary.
- Your unfinished work does not need its own working directory.
- You expect to return to the original task shortly.
Use Git Worktree When:
- You need to work on two branches for an extended period.
- You frequently switch between parallel tasks.
- You need both versions of the project available simultaneously.
Common Git Mistakes to Avoid
Running Git Reset Hard Without Checking Your Work
git status
Before destructive operations, make sure you understand which files and commits may be affected.
Force Pushing Shared Branches
Do not treat force push as a routine solution when Git rejects a push. First determine why the remote branch has changed.
Rebasing Shared History
Rebase creates new commit IDs. If teammates have already based their work on the original commits, rewriting that history can create unnecessary conflicts.
Committing API Keys or Credentials
Do not store secrets such as API keys, passwords, private certificates, access tokens, or production credentials. Simply deleting a secret in a later commit does not automatically remove it from previous Git history.
Creating Large Unrelated Commits
A good commit should represent one logical change whenever practical.
Smaller focused commits are easier to:
- Review
- Revert
- Debug
- Cherry-pick
- Understand later
Git in Modern Software Development and DevOps
Git is often the starting point for automated software delivery.
A modern development workflow may look like:
Developer → Git Commit → Pull Request → Automated Tests → Security Checks → Build → Deployment
Git events can trigger CI/CD pipelines that automatically validate and deploy software.
Teams building automated development and deployment workflows can explore our DevOps consulting services for CI/CD automation, infrastructure, observability, and release reliability, or our CI/CD DevOps consulting services for improving build, test, and deployment pipelines. For teams building or modernizing larger applications, our Web Application Development Services cover full-cycle product engineering, integrations, deployment, and continuous improvement.
Conclusion
A useful Git commands cheat sheet should go beyond `git add`, `git commit`, `git pull`, and `git push`.
Start with basic Git commands for repository setup, staging, committing, branches, and remote collaboration. Then learn commands such as `git stash`, `git restore`, `git revert`, and `git reflog` for everyday troubleshooting.
As your development workflows become more complex, advanced commands such as `git bisect`, `git worktree`, `git cherry-pick`, interactive rebase, fixup, and `–force-with-lease` provide greater control over debugging, repository history, and collaborative development.
You do not need to memorize every Git command. Keep this common Git commands cheat sheet available and focus on understanding which command solves each development problem.
Frequently Asked Questions
What are the most common Git commands?
Common Git commands include `git clone`, `git status`, `git add`, `git commit`, `git branch`, `git switch`, `git merge`, `git pull`, `git push`, and `git log`. These commands cover most everyday repository, branch, and collaboration workflows.
What is a Git commands cheat sheet?
A Git commands cheat sheet is a quick reference containing frequently used Git commands, syntax, and common use cases. Instead of memorizing every option, developers can use a cheat sheet to quickly identify the right command for a particular Git task.
What are the basic Git commands for beginners?
A useful basic Git commands cheat sheet should include `git init`, `git clone`, `git status`, `git add`, `git commit`, `git diff`, `git log`, `git branch`, `git switch`, `git pull`, and `git push`. After becoming comfortable with these commands, developers can learn more advanced tools such as stash, rebase, reflog, worktree, and bisect.
Are Git Bash commands different from Git commands?
Yes. Git commands include `git status`, `git commit`, `git pull`, and `git push`. Git Bash also provides shell commands such as `pwd`, `ls`, `cd`, and `mkdir`. Git Bash gives Windows users a Bash-style environment where both types of commands can be used.
What is the difference between Git fetch and Git pull?
`git fetch` downloads updates from a remote repository without automatically integrating them into your current branch. `git pull` retrieves remote updates and integrates them with your current branch according to the configured pull behavior.
What is the difference between Git reset and Git revert?
`git reset` moves repository references and can rewrite local history. `git revert` creates a new commit that reverses an earlier commit without deleting the existing history. For changes already shared with other developers, revert is generally the safer option.
How do I recover a lost Git commit?
Run `git reflog` and look for the previous commit or HEAD position. Depending on the situation, you can then create a branch from that commit or reset the branch to the appropriate state.
How can Git bisect help find a bug?
`git bisect` uses a binary-search process to identify the commit that introduced a problem. Mark one commit as good and another as bad, and Git checks commits between them until the problematic change is identified.
What is Git cherry-pick used for?
Git cherry-pick applies the changes from one specific commit to your current branch. It is useful when you need a particular bug fix or change without merging the entire source branch.
What is Git worktree used for?
`git worktree` allows multiple working directories to be connected to the same Git repository. It is useful when you need to work on several branches simultaneously without repeatedly stashing and switching branches.
When should I use Git rebase instead of merge?
Use rebase when you need to update or clean the history of your own local feature branch. Use merge when you want to combine development histories without rewriting existing commits. Avoid rebasing shared branches unless the team has coordinated the change.