WebGroundwebground.app
Info & Guides · Developer Reference

Git Commands Cheat Sheet

Searchable list of everyday Git commands for setup, staging, branching, remotes, undoing changes, and history, with warnings on destructive commands.

Showing 35 of 35
  • git config --global user.name "Your Name"
    What it does

    Set the name recorded in your commits.

  • git config --global user.email "[email protected]"
    What it does

    Set the email address recorded in your commits.

  • git init
    What it does

    Create a new repository in the current folder.

  • git clone <url>
    What it does

    Download a repository and its full history.

  • git status
    What it does

    Show changed, staged, and untracked files.

  • git add <file>
    What it does

    Stage a file for the next commit.

  • git add -A
    What it does

    Stage every change, including deleted files.

  • git add -p
    What it does

    Choose interactively which parts of your changes to stage.

  • git commit -m "message"
    What it does

    Record the staged changes as a new commit.

  • git commit --amend
    What it does

    Replace the last commit with a new message or extra changes.

    Discards work or rewrites history
  • git diff
    What it does

    Show changes that are not staged yet.

  • git diff --staged
    What it does

    Show changes that are staged for the next commit.

  • git branch
    What it does

    List local branches; the current one is marked with *.

  • git switch -c <branch>
    What it does

    Create a new branch and switch to it.

  • git switch <branch>
    What it does

    Switch to an existing branch.

  • git merge <branch>
    What it does

    Merge another branch into the current branch.

  • git rebase <branch>
    What it does

    Replay your commits on top of another branch.

    Discards work or rewrites history
  • git branch -d <branch>
    What it does

    Delete a local branch that has been merged.

  • git remote add origin <url>
    What it does

    Connect a remote repository under the name origin.

  • git fetch --prune
    What it does

    Download remote changes and remove references to branches deleted on the remote.

  • git pull
    What it does

    Fetch remote changes and integrate them into the current branch.

  • git push
    What it does

    Upload your local commits to the remote branch.

  • git push -u origin <branch>
    What it does

    Push a new branch and link it to the remote branch.

  • git restore <file>
    What it does

    Discard unstaged changes in a file.

    Discards work or rewrites history
  • git restore --staged <file>
    What it does

    Unstage a file but keep its changes.

  • git revert <commit>
    What it does

    Create a new commit that undoes an earlier commit.

  • git reset --soft HEAD~1
    What it does

    Undo the last commit but keep its changes staged.

    Discards work or rewrites history
  • git reset --hard <commit>
    What it does

    Move the branch to a commit and discard all local changes.

    Discards work or rewrites history
  • git log --oneline --graph
    What it does

    Show compact history with a branch graph.

  • git show <commit>
    What it does

    Show the message and changes of a commit.

  • git blame <file>
    What it does

    Show who last changed each line of a file.

  • git reflog
    What it does

    List recent HEAD positions to recover lost commits.

  • git stash
    What it does

    Save uncommitted changes and clean the working tree.

  • git stash pop
    What it does

    Re-apply the latest stash and remove it from the list.

  • git stash list
    What it does

    List all saved stashes.

The Everyday Git Workflow

Most work follows the same loop: check status, stage changes with git add, record them with git commit, and share them with git push. Branches keep unfinished work separate from the main line.

Commands marked with a warning discard changes or rewrite history. Use them carefully, especially on branches that other people have already pulled.

Undoing Mistakes Safely

Git rarely loses committed work for good.

  • Use git revert to undo a commit that is already pushed.
  • Use git restore --staged to unstage without losing edits.
  • git reflog lists recent HEAD positions, so you can recover commits after a reset.

Frequently Asked Questions

What is the difference between git switch and git checkout?+

git switch (added in Git 2.23) only changes branches, while git checkout also restores files. The newer switch and restore commands split those jobs to make mistakes less likely.

Should I merge or rebase?+

Merge keeps the exact history and is safest on shared branches. Rebase creates a cleaner, linear history but rewrites commits, so only rebase branches nobody else uses.

What does git fetch --prune do?+

It downloads new commits from the remote and removes local references to branches that were deleted on the remote.

Explore More on WebGround

View all