Modern Git Commands
Modern Git means the commands and options added since Git 2.23 (August 2019) that replace older, confusing or risky ways of doing things. The best known are git switch and git restore, which split the many jobs of git checkout into two clear commands, but there are many more: safer force pushes, background maintenance, sparse checkout, and clearer git config commands. Older commands still work, and most tutorials and answers online still use them, so it helps to know both: write modern commands yourself, and recognize the old ones when you read them. This page was last checked on November 15, 2026, against Git 2.53 (the latest release then was Git 2.56).
A new edition of a dictionary is a good comparison. The old words are still understood, but the new edition adds clearer ones, and a few old entries are marked "dated".
Old and New Side by Side
| Job | Older way | Modern way | Since |
|---|---|---|---|
| Switch branch | git checkout main | git switch main | 2.23 |
| Create and switch | git checkout -b feature | git switch -c feature | 2.23 |
| Discard changes to a file | git checkout -- fees.txt | git restore fees.txt | 2.23 |
| Unstage a file | git reset HEAD fees.txt | git restore --staged fees.txt | 2.23 |
| Get a file from another commit | git checkout v1.0 -- fees.txt | git restore --source=v1.0 fees.txt | 2.23 |
| Look at an old commit | git checkout <commit> | git switch --detach <commit> | 2.23 |
| Force push | git push --force | git push --force-with-lease --force-if-includes | 1.8.5, 2.30 |
| Stash with a message | git stash save "msg" | git stash push -m "msg" | 2.13 |
| Read a setting | git config user.name | git config get user.name | 2.46 |
| Write a setting | git config user.name "Navika" | git config set user.name "Navika" | 2.46 |
| Housekeeping | git gc by hand | git maintenance start | 2.30 |
| Only some folders | Manual .git/info/sparse-checkout | git sparse-checkout set (cone mode) | 2.25 |
| Merge strategy | recursive | ort (the default) | 2.34 |
Example 1: switch and restore Instead of checkout
git checkout does two very different jobs: changing branches and overwriting files. A typo can turn one into the other and lose work. The two modern commands each do one job:
mkdir fee-tracker
cd fee-tracker
git init --quiet
echo 'Term fee: $12,000' > fees.txt
git add fees.txt
git commit --quiet -m "Add the term fee"
git switch -c feature/late-fee
echo 'Late fee: $250' >> fees.txt
git restore fees.txt
git status --short
git switch mainSwitched to a new branch 'feature/late-fee'
Switched to branch 'main'Explanation: git switch -c created and switched to the branch, git restore fees.txt threw away the unsaved line, and git switch main went back. git switch refuses to take a file name, and git restore never changes branches, so neither can do the other's job by mistake. Git's own documentation says that checkout, switch and restore will all stay, so old scripts keep working.
Example 2: git config get and set
Since Git 2.46, git config has subcommands with clear names, like other commands:
git config set --global pull.rebase true
git config get pull.rebase
git config list --global
git config unset --global pull.rebase
git config get pull.rebase || echo "pull.rebase is not set"true
user.name=Navika Anamaneni
user.email=navika@example.com
init.defaultbranch=main
pull.rebase=true
pull.rebase is not setExplanation: set, get, list and unset replace the older forms git config <key> <value>, git config <key>, git config --list and git config --unset <key>, which still work. You have already seen the new form in Git's own hints, such as "Disable this message with git config set advice.mergeConflict false".
Example 3: Newer Commands Worth Knowing
git repo info references.format object.format
git refs list
git last-modifiedreferences.format=files
object.format=sha1
5c7eaa5e8c85f7c4ee0b62e8aa63fe8f6f812190 commit refs/heads/feature/late-fee
5c7eaa5e8c85f7c4ee0b62e8aa63fe8f6f812190 commit refs/heads/main
5c7eaa5e8c85f7c4ee0b62e8aa63fe8f6f812190 fees.txtExplanation: git repo info prints facts about the repository in a form scripts can read: here, that its references are stored in the files format and its object IDs use SHA-1 (both explained in "Git 3.0: What Is Planned"). git refs list lists references, like git for-each-ref. git last-modified shows, for each file, the last commit that changed it, as hosting platforms do in their file lists. All three were added in recent releases, so older Git versions don't have them, and their options may still change.
Other modern additions covered elsewhere in this course:
| Command or option | What it does | Lesson |
|---|---|---|
git push --force-with-lease --force-if-includes | Force push only if nobody else pushed meanwhile | "Force Push Safely" |
git rebase --update-refs | Move stacked branches along in a rebase | "Git Rebase" |
git maintenance start | Background housekeeping | "Keeping Repositories Fast" |
git sparse-checkout, --filter=blob:none | Work on huge repositories | "Git Sparse Checkout", "Shallow and Partial Clones" |
git backfill | Download missing file contents of a partial clone in batches | "Shallow and Partial Clones" |
git merge-tree --write-tree | Merge without a working folder | "How Git Merges" |
git log --remerge-diff | See how a merge's conflicts were resolved | "How Git Merges" |
SSH commit signing (gpg.format ssh) | Sign without GPG | "Signing Commits and Tags" |
push.autoSetupRemote | First git push sets the upstream | "Upstream and Remote-Tracking Branches" |
scalar | Settings for very large repositories | "Keeping Repositories Fast" |
How to Keep Up
Git releases a new version about every three months, with security and bug-fix releases in between.
- Release notes: each version's notes are in Git's source under
Documentation/RelNotes/, and announced on the Git mailing list. - Hosting platform blogs: GitHub's blog publishes a "Highlights from Git 2.xx" post for each release, and GitLab writes similar summaries.
- Your own Git:
git versionshows what you have,git help <command>opens the manual for exactly that version, andgit help -alists every command it knows. - Git's planned changes:
Documentation/BreakingChanges.adoclists what Git 3.0 will change (see "Git 3.0: What Is Planned").
git versiongit version 2.53.0Common Mistakes
Copying old answers without checking. git checkout -- . and git push --force work, but have safer modern equivalents.
Using a new command in a script that runs on an old Git. CI images and servers can be years behind. Check git version there, or stick to long-established commands in shared scripts.
Thinking checkout is deprecated. It isn't, and Git plans to keep it. The modern commands are simply clearer.
Never updating Git. Old versions miss security fixes as well as features.
Under the Hood
Git keeps old commands working for a long time, because millions of scripts depend on them. New behavior usually arrives in three steps: first as an option (--force-with-lease), then as a setting that changes the default (pull.rebase, push.autoSetupRemote), and only in a major version, such as the planned Git 3.0, as a new default. switch and restore are new front ends over the same internal code that checkout uses, which is why they behave identically for the jobs they share. Commands marked "EXPERIMENTAL" in their help, such as git replay, may still change their options between releases.
Interview Corner
What is the difference between git checkout, git switch and git restore?
checkout both switches branches and restores files. Since Git 2.23, switch only changes branches and restore only restores files, which avoids mistakes. All three are supported.
How do you unstage a file in modern Git?
git restore --staged <file>. The older form is git reset HEAD <file>.
Name some features added to Git in recent years.
switch and restore, --force-with-lease with --force-if-includes, git maintenance, sparse checkout in cone mode, the ort merge strategy, SSH signing, git config get/set, merge-tree --write-tree and --remerge-diff.
Practice
Challenge: modernize these commands. Rewrite git checkout -b feature/exam-fee, git checkout -- fees.txt and git reset HEAD fees.txt with modern commands, and run them on a change to fees.txt.
What does Git print? Before you open the solution, decide the short status after each step.
Show solution
git switch --quiet -c feature/exam-fee
echo 'Exam fee: $800' >> fees.txt
git add fees.txt
git restore --staged fees.txt
git status --short
git restore fees.txt
git status --short M fees.txtAfter git restore --staged, the change is no longer staged but still in the file ( M). After git restore, the file is back to its committed version, and the status is empty.
Checkpoint. Read the release notes of the newest Git version, pick three changes, and try each in a practice repository.
Key Takeaways
Quick reference
| Old | Modern |
|---|---|
git checkout <branch> | git switch <branch> |
git checkout -b <branch> | git switch -c <branch> |
git checkout -- <file> | git restore <file> |
git reset HEAD <file> | git restore --staged <file> |
git push --force | git push --force-with-lease |
git config <key> | git config get <key> |
Was this tutorial helpful?