CmdKeys LogoCommand Quiz

Git Command Practice

Git stores snapshots and moves branch pointers; the CLI is how you inspect and rewrite that history. This track drills status, add, commit, branch, rebase, restore, and worktrees as typed porcelain — the same verbs you need when a GUI is not available.

Command Reference

branches

CommandDescription
git branchList local branches and show the current branch.
git branch <name>Create a new branch without switching to it.
git branch -rList all remote-tracking branches in the repository.
git switch -c <branch>Create a new branch and switch to it.
git checkout -Quickly switch back to the previously checked-out branch.
git switch <branch>Switch to an existing branch.
git branch -vvList local branches with commit details and tracking upstream branches.
git checkout <branch> -- <file>Checkout a specific file version from another branch into the working tree.
git merge <branch>Merge another branch into the current branch.

basics

CommandDescription
git statusShow the working tree status and staged changes.
git clone <url>Clone a remote repository to your local machine.
git initInitialize a new Git repository in the current directory.

history

CommandDescription
git log -n <num>Limit commit history output to the last N entries.
git log --onelineShow commit history as one compact line per commit.
git log --grep=<pattern>Filter commits by commit message matching a search pattern.
git log -pShow line-by-line diff patch changes over time for commits.
git log --pretty=oneline --graph --decorate --allDisplay an ASCII graph of commit history across all branches.
git log --name-onlyList the names of changed files for each commit.
git log --no-merges --name-onlyList changed files in commits excluding merge commits.
git log --max-count=<num>Limit commit history output to a maximum of N commits.
git log --after="<date>"Show commits created after a specific date.
git log --before="<date>"Show commits created before a specific date.
git log --author=<pattern>Filter commits by author name or email pattern.
git log --graph --decorateShow an ASCII commit graph for the current branch with reference tags.
git reflogDisplay the local history of HEAD and branch reference updates.
git cherry-pick <commit>Apply one specific commit onto the current branch.
git rebase --continueContinue a rebase after resolving conflicts.
git rebase mainReplay current branch commits on top of main.

commits

CommandDescription
git commit -m "<message>"Create a commit with an inline commit message.
git commit --amend -m "<message>"Modify the commit message of the latest commit.
git commit --amend --no-editAdd staged changes to the latest commit without changing its message.

inspection

CommandDescription
git diffShow unstaged changes in the working tree.
git diff --stagedShow changes staged for the next commit.
git show <commit>Show details and patch for a specific commit.
git blame <file>Show the last commit that changed each line of a file.

remotes

CommandDescription
git remote -vList remotes with their fetch and push URLs.
git pullFetch from the configured remote and merge into the current branch.
git fetchDownload remote refs and objects without merging them.
git pushPush local commits to the configured upstream branch.
git push -u origin <branch>Push a branch and set its upstream to origin.
git remote add origin <url>Add a remote named origin for a repository URL.

staging

CommandDescription
git add .Stage all changed files under the current directory.
git add <file>Stage a specific file for the next commit.

undo

CommandDescription
git restore <file>Discard unstaged changes in a specific file.
git restore --staged <file>Unstage a file while keeping its working tree changes.
git reset --soft HEAD~1Undo the last commit while keeping changes staged.
git reset --hard HEADDiscard all tracked working tree and staged changes.

workflow

CommandDescription
git stashTemporarily save uncommitted changes and clean the working tree.
git stash popApply the latest stash and remove it from the stash list.

tags

CommandDescription
git tag <name>Create a lightweight tag at the current commit.
git tag -a <name> -m "<message>"Create an annotated tag with a message.

worktrees

CommandDescription
git worktree listList all active working tree directories linked to the repository.
git worktree add <dir> <branch>Create a new working tree directory linked to a specific branch.
git worktree remove <dir>Remove a linked working tree directory.
git worktree pruneClean up administrative information for manually deleted working trees.
git worktree move <dir> <new_dir>Move a working tree directory to a new path location.

submodules

CommandDescription
git clone --recursive <url>Clone a repository and automatically initialize all submodules.
git submodule updateUpdate submodules to match the commit specified in the superproject.
git submodule add <url>Add a new external Git repository as a submodule.
git submodule update --remoteFetch and update submodules to their remote branch's latest commit.
git submodule deinit <dir>Unregister a submodule from the repository configuration.

config

CommandDescription
git config --global alias.<alias> <command>Define a global Git command shortcut alias.

cleanup

CommandDescription
git clean -fdnPreview untracked files and directories that would be removed.
git clean -fdRemove untracked files and directories from the working tree.

Key Use Cases

  • See what will be committed before you write a snapshot
  • Rewrite the last commit message without changing the tree
  • Restore a file you deleted in the working tree
  • Rebase a feature branch onto updated main
  • Park unfinished work with stash and come back later

Frequently Asked Questions

When should I use git commit --amend instead of a new commit?

Amend rewrites HEAD. Use it only for the commit you just made and have not pushed, or when you own the branch and will force-push on purpose.

What is the difference between git restore and git checkout?

restore changes files or the index. switch/checkout move HEAD. Older git used checkout for both, which is why this track treats them as separate prompts.

Is rebase safer than merge?

Rebase replays your commits on a new base and rewrites hashes. Merge adds a join commit and keeps history. Neither is always safer; this track tests when each command is the one you type.

Why practice the Git CLI if I use a GUI?

Hooks, CI, and ssh sessions still expect porcelain. A GUI click does not train git rebase --onto or git restore --staged.

Ready to master Git commands?

Test your muscle memory with our spaced-repetition quiz system. Free forever.

Start Practice Now →