<div class="wpcnt">
			<div class="wpa">
				<span class="wpa-about">Advertisements</span>
				<div class="u top_amp">
							<amp-ad width="300" height="265"
		 type="pubmine"
		 data-siteid="173035871"
		 data-section="1">
		</amp-ad>
				</div>
			</div>
		</div><p dir="ltr">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&#8217;s official documentation, and flags what is coming in Git 3.0.</p>
<h2 dir="ltr">What Is New in Git</h2>
<p dir="ltr">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&#8217;s &#8220;Highlights from Git 2.56&#8221; (September 28, 2026) lists git add &#8211;resolved, git branch &#8211;delete-merged with a &#8211;dry-run option, git bisect run &#8211;reset-when-found, and git replay &#8211;linearize.</p>
<h3 dir="ltr"><strong>Git 3.0 Is Coming, With No Date</strong></h3>
<p dir="ltr">Git&#8217;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 &#8220;There is no planned release date&#8221; and that git checkout is not deprecated.</p>
<h2 dir="ltr">Setup</h2>
<p dir="ltr">Set your name with the classic form git config &#8211;global user.name &#8220;Your Name&#8221;. Git 2.56&#8217;s documentation also shows git config set &#8211;global user.name &#8220;Your Name&#8221; 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 &#8220;currently master, but this will change to main when Git 3.0 is released,&#8221; and that you can override it with init.defaultBranch or the -b option.</p>
<h2 dir="ltr">Switching Branches</h2>
<p dir="ltr">git switch -c new-branch creates and switches. git switch &#8211; returns to the previous branch. git switch &#8211;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.</p>
<h2 dir="ltr">Undoing Changes to Files</h2>
<p dir="ltr">git restore file discards working-tree changes. git restore &#8211;staged file unstages. git restore &#8211;source=commit file restores a file from a given commit. The docs&#8217; examples include git restore &#8211;staged hello.c and git restore &#8211;source master~2 Makefile. With &#8211;staged the source defaults to HEAD, otherwise to the index. Remember that discarding working changes cannot be undone.</p>
<h2 dir="ltr">Committing</h2>
<p dir="ltr">git commit &#8211;amend &#8211;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.</p>
<h2 dir="ltr">Syncing With a Remote</h2>
<p dir="ltr">git fetch downloads updates and writes .git/FETCH_HEAD. Add &#8211;prune to remove stale remote-tracking branches, or &#8211;all for every remote. git pull supports &#8211;rebase and &#8211;ff-only, where &#8211;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.</p>
<p dir="ltr">git push -u origin branch sets upstream tracking. git push &#8211;delete origin branch removes a remote branch. For force pushes, prefer &#8211;force-with-lease: per the docs, it overrides the fast-forward restriction only &#8220;if the current value of the remote ref is the expected value,&#8221; while plain &#8211;force &#8220;can cause the remote repository to lose commits.&#8221; The &#8211;force-if-includes option adds a companion check.</p>
<h2 dir="ltr">Stashing</h2>
<p dir="ltr">git stash push -u -m &#8220;message&#8221; 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.</p>
<h2 dir="ltr">Resetting and Reverting</h2>
<p dir="ltr">git reset defaults to &#8211;mixed. git reset &#8211;soft HEAD~1 undoes the last commit but keeps changes staged; the docs note that git reset &#8211;soft HEAD~5 followed by git commit squashes the last five commits. git reset &#8211;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.</p>
<h2 dir="ltr">Cherry-Picking</h2>
<p dir="ltr">git cherry-pick commit applies a commit elsewhere. The -x flag appends a &#8220;(cherry picked from commit &#8230;)&#8221; line. For merge commits, -m with a parent number is required. Use &#8211;continue, &#8211;skip, &#8211;abort, or &#8211;quit when conflicts interrupt.</p>
<h2 dir="ltr">Looking Around</h2>
<p dir="ltr">git log &#8211;oneline &#8211;graph &#8211;all &#8211;decorate shows a compact picture of branches. The docs say &#8211;oneline is shorthand for &#8211;pretty=oneline &#8211;abbrev-commit. git reflog, an alias of git log -g &#8211;abbrev-commit &#8211;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.</p>
<h2 dir="ltr">Finding Bugs With Bisect</h2>
<p dir="ltr">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.</p>
<h2 dir="ltr">Working on Two Branches at Once</h2>
<p dir="ltr">git worktree add -b emergency-fix ../temp master creates a second working directory, as in the documentation&#8217;s example, and git worktree remove ../temp cleans it up. List and prune are also available.</p>
<h2 dir="ltr">Ignoring Files</h2>
<p dir="ltr">In .gitignore, a trailing slash matches directories only, an exclamation mark negates a pattern, and patterns like <strong>/foo, a/</strong>/b, and abc/** work. The docs warn: &#8220;It is not possible to re-include a file if a parent directory of that file is excluded.&#8221; For files already tracked, run git rm &#8211;cached.</p>
<h2 dir="ltr">Quick Reference</h2>
<div dir="ltr">
<table>
<thead>
<tr>
<th scope="col">Task</th>
<th scope="col">Command</th>
</tr>
</thead>
<tbody>
<tr>
<td>New repo with main branch</td>
<td>git init -b main</td>
</tr>
<tr>
<td>New branch</td>
<td>git switch -c name</td>
</tr>
<tr>
<td>Unstage a file</td>
<td>git restore &#8211;staged file</td>
</tr>
<tr>
<td>Fix last commit</td>
<td>git commit &#8211;amend &#8211;no-edit</td>
</tr>
<tr>
<td>Safe force push</td>
<td>git push &#8211;force-with-lease</td>
</tr>
<tr>
<td>Save work temporarily</td>
<td>git stash push -u -m &#8220;msg&#8221;</td>
</tr>
<tr>
<td>Undo a commit safely</td>
<td>git revert commit</td>
</tr>
<tr>
<td>Compact history</td>
<td>git log &#8211;oneline &#8211;graph &#8211;all &#8211;decorate</td>
</tr>
<tr>
<td>Find a bug</td>
<td>git bisect run command</td>
</tr>
</tbody>
</table>
</div>
<h2 dir="ltr">Safety Rules</h2>
<p dir="ltr">Do not rewrite history that others have pulled. Prefer revert on shared branches. Use &#8211;force-with-lease, never plain &#8211;force. Check git status before reset &#8211;hard. Remember that reflog can rescue recent mistakes but expires.</p>
<h2 dir="ltr">Building Good Habits</h2>
<p dir="ltr">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&#8217;s configuration. Before a risky operation such as reset &#8211;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.</p>
<h2 dir="ltr">A Recovery Playbook</h2>
<p dir="ltr">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 &#8211;abort is the usual way out, though the merge documentation was not reviewed for this article, so confirm in git help merge.</p>
<h2 dir="ltr">Tools Worth Knowing About</h2>
<p dir="ltr">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 &#8211;delete-merged with &#8211;dry-run, help keep a repository tidy. Because Git evolves, check the release notes when you upgrade.</p>
<h2 dir="ltr">Understanding the Three Areas of Git</h2>
<p dir="ltr">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 &#8211;staged, moves content back. git reset has soft, mixed, and hard modes that affect different areas: &#8211;soft leaves the working tree and index alone, the default &#8211;mixed resets the index, and &#8211;hard overwrites files. Once you picture the three areas, the command names make sense.</p>
<h2 dir="ltr">Merge Versus Rebase</h2>
<p dir="ltr">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 &#8211;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&#8217;s warning about rewriting published history.</p>
<h2 dir="ltr">Configuring Git Sensibly</h2>
<p dir="ltr">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 &#8211;list shows what you have set.</p>
<h2 dir="ltr">Learning by Practicing Safely</h2>
<p dir="ltr">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.</p>
<h2 dir="ltr">Commands for Collaboration</h2>
<p dir="ltr">When working with a team, learn the commands that keep history readable. git fetch &#8211;prune keeps your list of remote branches tidy. git pull &#8211;ff-only refuses to create a merge commit when your branch has diverged, which can prevent accidental merges. git push &#8211;force-with-lease protects teammates&#8217; work. git cherry-pick -x leaves a trace of where a commit came from. git log &#8211;oneline &#8211;graph &#8211;all &#8211;decorate shows the shape of the repository. Together these form a safe, readable workflow for a small team.</p>
<h2 dir="ltr">Reading the Documentation</h2>
<p dir="ltr">Git&#8217;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.</p>
<h2 dir="ltr">Frequently Asked Questions</h2>
<h3 dir="ltr">What is the latest version of Git?</h3>
<p dir="ltr">2.56.0, according to git-scm.com.</p>
<h3 dir="ltr">Is git checkout deprecated?</h3>
<p dir="ltr">No. Git&#8217;s documentation says it is not, though git switch and git restore split its roles.</p>
<h3 dir="ltr">What is the difference between reset and revert?</h3>
<p dir="ltr">Reset moves the branch pointer and can discard work. Revert adds a new commit that undoes an older one.</p>
<h3 dir="ltr">Will the default branch change to main?</h3>
<p dir="ltr">In Git 3.0, for which there is no planned date.</p>
<h3 dir="ltr">How do I recover a lost commit?</h3>
<p dir="ltr">Check git reflog, whose entries last 90 days, or 30 if unreachable.</p>
<h2 dir="ltr"><strong>References and Sources</strong></h2>
<p dir="ltr">Git, &#8220;Install from source&#8221;: <a href="https://git-scm.com/install/source">https://git-scm.com/install/source</a></p>
<p dir="ltr">Git, &#8220;Release notes 2.56.0&#8221;: <a href="https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.56.0.adoc">https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.56.0.adoc</a></p>
<p dir="ltr">GitHub Blog, &#8220;Highlights from Git 2.56&#8221;: <a href="https://github.blog/open-source/git/highlights-from-git-2-56/">https://github.blog/open-source/git/highlights-from-git-2-56/</a></p>
<p dir="ltr">Git, &#8220;BreakingChanges&#8221;: <a href="https://git-scm.com/docs/BreakingChanges">https://git-scm.com/docs/BreakingChanges</a></p>
<p dir="ltr">Git, &#8220;git-init&#8221;: <a href="https://git-scm.com/docs/git-init">https://git-scm.com/docs/git-init</a></p>
<p dir="ltr">Git, &#8220;git-switch&#8221;: <a href="https://git-scm.com/docs/git-switch">https://git-scm.com/docs/git-switch</a></p>
<p dir="ltr">Git, &#8220;git-restore&#8221;: <a href="https://git-scm.com/docs/git-restore">https://git-scm.com/docs/git-restore</a></p>
<p dir="ltr">Git, &#8220;git-checkout&#8221;: <a href="https://git-scm.com/docs/git-checkout">https://git-scm.com/docs/git-checkout</a></p>
<p dir="ltr">Git, &#8220;git-reset&#8221;: <a href="https://git-scm.com/docs/git-reset">https://git-scm.com/docs/git-reset</a></p>
<p dir="ltr">Git, &#8220;git-commit&#8221;: <a href="https://git-scm.com/docs/git-commit">https://git-scm.com/docs/git-commit</a></p>
<p dir="ltr">Git, &#8220;git-push&#8221;: <a href="https://git-scm.com/docs/git-push">https://git-scm.com/docs/git-push</a></p>
<p dir="ltr">Git, &#8220;git-pull&#8221;: <a href="https://git-scm.com/docs/git-pull">https://git-scm.com/docs/git-pull</a></p>
<p dir="ltr">Git, &#8220;git-fetch&#8221;: <a href="https://git-scm.com/docs/git-fetch">https://git-scm.com/docs/git-fetch</a></p>
<p dir="ltr">Git, &#8220;git-stash&#8221;: <a href="https://git-scm.com/docs/git-stash">https://git-scm.com/docs/git-stash</a></p>
<p dir="ltr">Git, &#8220;git-cherry-pick&#8221;: <a href="https://git-scm.com/docs/git-cherry-pick">https://git-scm.com/docs/git-cherry-pick</a></p>
<p dir="ltr">Git, &#8220;git-revert&#8221;: <a href="https://git-scm.com/docs/git-revert">https://git-scm.com/docs/git-revert</a></p>
<p dir="ltr">Git, &#8220;git-reflog&#8221;: <a href="https://git-scm.com/docs/git-reflog">https://git-scm.com/docs/git-reflog</a></p>
<p dir="ltr">Git, &#8220;git-bisect&#8221;: <a href="https://git-scm.com/docs/git-bisect">https://git-scm.com/docs/git-bisect</a></p>
<p dir="ltr">Git, &#8220;git-worktree&#8221;: <a href="https://git-scm.com/docs/git-worktree">https://git-scm.com/docs/git-worktree</a></p>
<p dir="ltr">Git, &#8220;git-log&#8221;: <a href="https://git-scm.com/docs/git-log">https://git-scm.com/docs/git-log</a></p>
<p dir="ltr">Git, &#8220;gitignore&#8221;: <a href="https://git-scm.com/docs/gitignore">https://git-scm.com/docs/gitignore</a></p>
<p dir="ltr">Git, &#8220;git-config&#8221;: <a href="https://git-scm.com/docs/git-config">https://git-scm.com/docs/git-config</a></p>

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

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