Git Commands Cheat Sheet for Developers: The Most Used Commands in 2026

As of October 27, 2026, the current Git release is 2.56.0, and the commands you use every day have barely changed: init, add, commit, switch, restore, push, pull, stash, reset, revert, and log. What has changed is the recommended style. Since Git 2.23, git switch changes branches and git restore fixes files, splitting the old overloaded git checkout, which is not deprecated. This cheat sheet groups the most useful commands by task, with the safety notes from Git’s official documentation, and flags what is coming in Git 3.0.

What Is New in Git

git-scm.com lists Git 2.56.0 as the latest source release. The release notes mention a new git refs command for creating, deleting, updating, and renaming references, an experimental git history drop, and extra advice in git status. GitHub’s “Highlights from Git 2.56” (September 28, 2026) lists git add –resolved, git branch –delete-merged with a –dry-run option, git bisect run –reset-when-found, and git replay –linearize.

Git 3.0 Is Coming, With No Date

Git’s BreakingChanges page lists plans for Git 3.0: the default branch name main, sha256 as the default hash, reftable as the default reference storage, Rust becoming mandatory, safe.bareRepository defaulting to explicit instead of all, and removal of grafts, git-pack-redundant, and git-whatchanged. It says “There is no planned release date” and that git checkout is not deprecated.

Setup

Set your name with the classic form git config –global user.name “Your Name”. Git 2.56’s documentation also shows git config set –global user.name “Your Name” and git config get for reading values. Create a repository with git init -b main. The git-init documentation says the default branch name is “currently master, but this will change to main when Git 3.0 is released,” and that you can override it with init.defaultBranch or the -b option.

Switching Branches

git switch -c new-branch creates and switches. git switch – returns to the previous branch. git switch –detach commit checks out a commit without a branch. The git checkout documentation still shows git checkout -b foo with the note that you can use git switch -c foo instead.

Undoing Changes to Files

git restore file discards working-tree changes. git restore –staged file unstages. git restore –source=commit file restores a file from a given commit. The docs’ examples include git restore –staged hello.c and git restore –source master~2 Makefile. With –staged the source defaults to HEAD, otherwise to the index. Remember that discarding working changes cannot be undone.

Committing

git commit –amend –no-edit adds staged changes to the last commit without changing its message. The documentation warns about rewriting published history. The -a flag stages modified and deleted files but not new files.

Syncing With a Remote

git fetch downloads updates and writes .git/FETCH_HEAD. Add –prune to remove stale remote-tracking branches, or –all for every remote. git pull supports –rebase and –ff-only, where –ff-only fails if your local branch has diverged. The config options pull.rebase and pull.ff control this. The fetched documentation text was contradictory about the default, so check git help pull on your machine.

git push -u origin branch sets upstream tracking. git push –delete origin branch removes a remote branch. For force pushes, prefer –force-with-lease: per the docs, it overrides the fast-forward restriction only “if the current value of the remote ref is the expected value,” while plain –force “can cause the remote repository to lose commits.” The –force-if-includes option adds a companion check.

Stashing

git stash push -u -m “message” saves work, including untracked files, with a label. git stash list shows saved stashes. git stash pop applies and removes the latest. Other subcommands are apply, drop, and show. The older git stash save is deprecated in favor of push.

Resetting and Reverting

git reset defaults to –mixed. git reset –soft HEAD~1 undoes the last commit but keeps changes staged; the docs note that git reset –soft HEAD~5 followed by git commit squashes the last five commits. git reset –hard commit overwrites files and may overwrite untracked ones, so use it carefully. git revert commit creates a new commit that reverses an earlier one, which is the safe option for shared branches.

Cherry-Picking

git cherry-pick commit applies a commit elsewhere. The -x flag appends a “(cherry picked from commit …)” line. For merge commits, -m with a parent number is required. Use –continue, –skip, –abort, or –quit when conflicts interrupt.

Looking Around

git log –oneline –graph –all –decorate shows a compact picture of branches. The docs say –oneline is shorthand for –pretty=oneline –abbrev-commit. git reflog, an alias of git log -g –abbrev-commit –pretty=oneline, records where HEAD has been. Its entries expire after 90 days, or 30 days if unreachable, which makes it a safety net for mistakes with reset and rebase.

Finding Bugs With Bisect

git bisect start, then git bisect bad and git bisect good with a known good commit, narrows down which commit introduced a bug. git bisect run command automates it: exit code 0 means good, 1 to 127 except 125 means bad, and 125 means skip. Finish with git bisect reset.

Working on Two Branches at Once

git worktree add -b emergency-fix ../temp master creates a second working directory, as in the documentation’s example, and git worktree remove ../temp cleans it up. List and prune are also available.

Ignoring Files

In .gitignore, a trailing slash matches directories only, an exclamation mark negates a pattern, and patterns like /foo, a//b, and abc/** work. The docs warn: “It is not possible to re-include a file if a parent directory of that file is excluded.” For files already tracked, run git rm –cached.

Quick Reference

Task Command
New repo with main branch git init -b main
New branch git switch -c name
Unstage a file git restore –staged file
Fix last commit git commit –amend –no-edit
Safe force push git push –force-with-lease
Save work temporarily git stash push -u -m “msg”
Undo a commit safely git revert commit
Compact history git log –oneline –graph –all –decorate
Find a bug git bisect run command

Safety Rules

Do not rewrite history that others have pulled. Prefer revert on shared branches. Use –force-with-lease, never plain –force. Check git status before reset –hard. Remember that reflog can rescue recent mistakes but expires.

Building Good Habits

Commit small and often, with messages that say why a change was made. Create a branch for each task. Pull with care: decide with your team whether to rebase or merge, and set pull.rebase or pull.ff accordingly, since both options exist in Git’s configuration. Before a risky operation such as reset –hard or a rebase, create a temporary branch at the current commit so you have a named safety point. The reflog is a backstop, but its entries expire.

A Recovery Playbook

If you committed to the wrong branch, create the right branch at that commit, then move the wrong branch back. If you amended and lost something, check git reflog for the earlier commit. If a bad commit is already pushed to a shared branch, use git revert, not a force push. If you are not sure what a command will do, run git status and git log first, and check the documentation page for the command. If a merge becomes a mess, git merge –abort is the usual way out, though the merge documentation was not reviewed for this article, so confirm in git help merge.

Tools Worth Knowing About

Git worktrees let you keep two branches checked out in separate folders, which avoids stashing for urgent fixes. Bisect automates the search for a bad commit, which is invaluable on long histories. And the 2.56 additions, such as branch –delete-merged with –dry-run, help keep a repository tidy. Because Git evolves, check the release notes when you upgrade.

Understanding the Three Areas of Git

Git keeps your work in three places: the working tree where you edit files, the index where you stage changes, and the repository where commits live. Many commands move changes between these places. git add moves changes from the working tree to the index. git commit moves them from the index to the repository. git restore, with or without –staged, moves content back. git reset has soft, mixed, and hard modes that affect different areas: –soft leaves the working tree and index alone, the default –mixed resets the index, and –hard overwrites files. Once you picture the three areas, the command names make sense.

Merge Versus Rebase

Merging combines histories and keeps a record of the join. Rebasing replays your commits on top of another branch, giving a straighter history. The git pull command supports both approaches through its –rebase option. This article did not review the merge and rebase documentation pages, so for the exact options, run git help merge and git help rebase. A safe guideline is to avoid rebasing commits that others have already pulled, consistent with the commit documentation’s warning about rewriting published history.

Configuring Git Sensibly

Beyond your name and email, consider setting init.defaultBranch to main now, so new repositories match the planned Git 3.0 default. Consider pull.rebase or pull.ff to make pulls predictable. Consider a global gitignore for editor files. The git-config documentation lists the available options, and git config –list shows what you have set.

Learning by Practicing Safely

Create a throwaway repository and try each command on it. Make commits, create branches, stash, reset, revert, and look at git reflog after each. Because the reflog records where HEAD has been for 90 days, you can usually return to an earlier state if you slip. That safe practice builds confidence faster than reading.

Commands for Collaboration

When working with a team, learn the commands that keep history readable. git fetch –prune keeps your list of remote branches tidy. git pull –ff-only refuses to create a merge commit when your branch has diverged, which can prevent accidental merges. git push –force-with-lease protects teammates’ work. git cherry-pick -x leaves a trace of where a commit came from. git log –oneline –graph –all –decorate shows the shape of the repository. Together these form a safe, readable workflow for a small team.

Reading the Documentation

Git’s manual pages are long, but the synopsis at the top of each page tells you what options exist. For example, git switch has forms for an existing branch, a detached commit, and a new branch created with -c or -C. Reading the synopsis first, then the examples, then the specific option you need is faster than reading top to bottom. The online documentation at git-scm.com mirrors the manual pages on your machine, which you can open with git help followed by the command name.

Frequently Asked Questions

What is the latest version of Git?

2.56.0, according to git-scm.com.

Is git checkout deprecated?

No. Git’s documentation says it is not, though git switch and git restore split its roles.

What is the difference between reset and revert?

Reset moves the branch pointer and can discard work. Revert adds a new commit that undoes an older one.

Will the default branch change to main?

In Git 3.0, for which there is no planned date.

How do I recover a lost commit?

Check git reflog, whose entries last 90 days, or 30 if unreachable.

References and Sources

Git, “Install from source”: https://git-scm.com/install/source

Git, “Release notes 2.56.0”: https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.56.0.adoc

GitHub Blog, “Highlights from Git 2.56”: https://github.blog/open-source/git/highlights-from-git-2-56/

Git, “BreakingChanges”: https://git-scm.com/docs/BreakingChanges

Git, “git-init”: https://git-scm.com/docs/git-init

Git, “git-switch”: https://git-scm.com/docs/git-switch

Git, “git-restore”: https://git-scm.com/docs/git-restore

Git, “git-checkout”: https://git-scm.com/docs/git-checkout

Git, “git-reset”: https://git-scm.com/docs/git-reset

Git, “git-commit”: https://git-scm.com/docs/git-commit

Git, “git-push”: https://git-scm.com/docs/git-push

Git, “git-pull”: https://git-scm.com/docs/git-pull

Git, “git-fetch”: https://git-scm.com/docs/git-fetch

Git, “git-stash”: https://git-scm.com/docs/git-stash

Git, “git-cherry-pick”: https://git-scm.com/docs/git-cherry-pick

Git, “git-revert”: https://git-scm.com/docs/git-revert

Git, “git-reflog”: https://git-scm.com/docs/git-reflog

Git, “git-bisect”: https://git-scm.com/docs/git-bisect

Git, “git-worktree”: https://git-scm.com/docs/git-worktree

Git, “git-log”: https://git-scm.com/docs/git-log

Git, “gitignore”: https://git-scm.com/docs/gitignore

Git, “git-config”: https://git-scm.com/docs/git-config

About The Author

Written By

I write about AI, Web3, Crypto, Fintech, and the technologies shaping the digital economy. Connect with me on LinkedIn: https://www.linkedin.com/in/kenneth-onyebuchi-3b4634228

More From Author

Leave a Reply

You May Also Like

How to Optimize Web Vitals (LCP, INP, CLS) for Google SEO Ranking in 2026

How to Optimize Web Vitals (LCP, INP, CLS) for Google SEO Ranking in 2026

To pass Core Web Vitals, aim for a Largest Contentful Paint of 2.5 seconds or…

WebSockets vs Server-Sent Events vs Polling: Choosing the Right Tool for Real-Time Apps

WebSockets vs Server-Sent Events vs Polling: Choosing the Right Tool for Real-Time Apps

Use server-sent events (SSE) when the server only needs to push updates to the browser,…

Top VS Code Extensions for AI Coding and Productivity in 2026

Top VS Code Extensions for AI Coding and Productivity in 2026

The most-installed AI coding extensions for VS Code in 2026 are GitHub Copilot and Copilot…