Overview of This Git Cheat Sheet

If you’re looking for the most practical and complete Git Cheat Sheet, you’ve come to the right place. Git is the most widely used version control system, trusted by developers, teams, and companies worldwide to manage source code and collaborate efficiently. This Git reference guide by Solviyo is your one-stop resource — whether you’re a beginner learning Git basics or an experienced developer working on complex projects.

In this cheat sheet, you’ll find all the essential Git commands with examples, organized into clear sections such as repository setup, branching, merging, stashing, undoing mistakes, and working with remote repositories like GitHub, GitLab, and Bitbucket. Each command is explained in simple language, so you’ll know not only what to type but also why and when to use it.

We’ve included both beginner-friendly 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 discover common Git workflows for solo projects and team collaboration, along with quick fixes for errors like merge conflicts or accidental commits.

Whether you’re preparing for a coding interview, contributing to open-source projects, or just need a handy Git commands list, this page is structured to make your workflow smoother. For convenience, you can also download the Git Cheat Sheet PDF and keep it handy on your desktop or mobile. Bookmark this guide — it’s your ultimate Git quick reference.

Quick Setup & Configuration

Before using Git, configure your identity and preferences. These commands help set up your name, email, and default settings:

CommandDescription
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 --listCheck all Git configuration settings.
git config --global core.editor "code --wait"Set default code editor (example: VS Code).
git config --global init.defaultBranch mainSet default branch name to main instead of master.
💡 Tip: Use --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:

CommandDescription
git initCreate a new local repository in the current directory.
git cloneClone an existing remote repository (GitHub, GitLab, etc.) to your machine.
git statusCheck the current status of your working directory (changes, staging, branch).
git logView commit history of the repository.
git log --oneline --graph --decorateView a simplified, graphical commit history.
💡 Tip: After 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.

CommandDescription
git branchList all local branches.
git branchCreate a new branch.
git checkoutSwitch to an existing branch.
git checkout -bCreate and switch to a new branch in one step.
git mergeMerge the specified branch into the current branch.
git branch -dDelete a branch safely (only if it’s been merged).
git branch -DForce delete a branch (even if not merged).
💡 Tip: Use feature branches for new work, then merge them into 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.

CommandDescription
git remote -vShow all remotes linked to the repository.
git remote add originAdd a new remote repository (commonly named origin).
git push -u origin mainPush commits to the remote repository and set upstream branch.
git fetch originDownload objects and refs from the remote (does not merge).
git pullFetch and merge changes from the remote into the current branch.
git pushPush local commits to the remote repository.
git remote remove originRemove a remote connection.
💡 Tip: Always 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.

CommandDescription
git restoreDiscard changes in the working directory (restore file from last commit).
git restore --stagedUnstage a file (move it back from staging area to working directory).
git reset HEAD~1Undo the last commit but keep the changes staged.
git reset --hard HEAD~1Completely remove the last commit and its changes (⚠ irreversible).
git commit --amendEdit the last commit (message or staged changes).
git revertCreate a new commit that reverses the changes of a previous commit (safe for shared repos).
💡 Tip: Use 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.

CommandDescription
git stashSave uncommitted changes and clean working directory.
git stash save "message"Save changes with a custom message for clarity.
git stash listView the list of stashed changes.
git stash applyApply the most recent stash (keeps it in stash list).
git stash popApply the most recent stash and remove it from stash list.
git stash drop stash@{n}Remove a specific stash entry.
git stash clearRemove all stashed entries.
💡 Tip: Use 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.

CommandDescription
git rebaseReapply commits on top of another base branch (cleaner history).
git rebase -i HEAD~nInteractive rebase to squash, reorder, or edit commits.
git cherry-pickApply a specific commit from another branch to the current branch.
git bisectBinary search to find the commit that introduced a bug.
git blameShow who last modified each line of a file (great for debugging).
git shortlog -snSee contribution summary by author (useful for stats).
git aliasCreate shortcuts for frequently used Git commands.
git config --global alias.co checkoutExample: create alias git co for git checkout.
💡 Tip: Use 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.

WorkflowSteps & Description
Solo Developer Workflow

Ideal for personal projects or small scripts where you’re the only contributor. The basic cycle is:

git initgit addgit commitgit push

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:

git clonegit branchgit checkoutgit commitgit push → Pull Request → git merge

This keeps the main branch stable while encouraging peer review and continuous integration.

Feature Branch Workflow

A variation of team workflow where every new feature or bug fix is developed on a dedicated branch:

git checkout -b feature/xyz → work & commit → git push → PR → git merge

This workflow makes tracking features easier and avoids cluttering the main branch with incomplete code.

💡 Tip: Solo developers can keep things simple, but teams should always use branches and pull requests to maintain code quality and history.