Skip to content
M2TOOLKIT

Git Command Helper

Describe what you want to do and get the git command for it.

  • Free
  • No sign-up
  • Nothing is sent or stored
  • Start a new repository

    git init

    Creates a .git folder in the current directory.

  • Copy a remote repository

    git clone https://github.com/user/repo.git

    Add a folder name at the end to clone into a different folder.

  • Set your name and email

    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"

    Used on every commit you make.

  • See what has changed

    git status

    Shows staged, unstaged and untracked files.

  • Stage all changes

    git add -A

    Use git add <file> to stage a single file.

  • Commit staged changes

    git commit -m "Describe your change"

    Write the message in the imperative: “Add login page”.

  • Push commits to the remote

    git push

    The first time on a new branch: git push -u origin <branch>.

  • Get the latest changes

    git pull

    Equivalent to git fetch followed by git merge (or rebase if configured).

  • See the differences in your files

    git diff

    Add --staged to see changes already added.

  • Create and switch to a new branch

    git switch -c feature/my-branch

    Older equivalent: git checkout -b feature/my-branch.

  • Switch to an existing branch

    git switch main

    Commit or stash your changes first.

  • List branches

    git branch -a

    -a includes remote branches.

  • Merge a branch into the current one

    git merge feature/my-branch

    Resolve any conflicts, then commit.

  • Rebase onto the latest main

    git fetch origin
    git rebase origin/main

    Rewrites your branch's commits on top of main — avoid on shared branches.

  • Delete a local branch

    git branch -d feature/my-branch

    Use -D to force-delete an unmerged branch.

  • Delete a remote branch

    git push origin --delete feature/my-branch

    Removes the branch from the remote repository.

  • Discard changes to a file

    git restore path/to/file

    Permanently loses uncommitted edits to that file.

  • Unstage a file

    git restore --staged path/to/file

    Keeps your edits, just removes them from the next commit.

  • Change the last commit message

    git commit --amend -m "New message"

    Only before pushing — amending rewrites history.

  • Add forgotten files to the last commit

    git add forgotten-file
    git commit --amend --no-edit

    Only before pushing.

  • Undo the last commit but keep the changes

    git reset --soft HEAD~1

    The changes stay staged.

  • Undo a pushed commit safely

    git revert <commit-hash>

    Creates a new commit that reverses it — safe on shared branches.

  • Throw away all local changes

    git reset --hard HEAD

    Destructive: uncommitted work is lost.

  • Recover a lost commit

    git reflog
    git switch -c recovered <hash>

    The reflog remembers where HEAD has been for about 90 days.

  • Save work in progress for later

    git stash push -m "wip"

    Add -u to include untracked files.

  • Bring stashed work back

    git stash pop

    git stash list shows all stashes.

  • View commit history compactly

    git log --oneline --graph --decorate -20

    Shows the last 20 commits with branches.

  • See who changed each line

    git blame path/to/file

    Add -L 10,20 to limit to lines 10–20.

  • Find which commit introduced a bug

    git bisect start
    git bisect bad
    git bisect good <known-good-hash>

    Git checks out commits for you to test; finish with git bisect reset.

  • Copy one commit onto your branch

    git cherry-pick <commit-hash>

    Applies that commit's changes as a new commit.

  • Show configured remotes

    git remote -v
  • Add a remote

    git remote add origin https://github.com/user/repo.git
  • Change a remote's URL

    git remote set-url origin git@github.com:user/repo.git

    Useful when switching from HTTPS to SSH.

  • Force-push safely after a rebase

    git push --force-with-lease

    Refuses to overwrite commits you haven't seen.

  • Create a release tag

    git tag -a v1.0.0 -m "Release 1.0.0"
    git push origin v1.0.0

    Annotated tags store the author and date.

  • Remove untracked files

    git clean -n
    git clean -fd

    -n is a dry run; -fd deletes files and folders.

  • Stop tracking a file but keep it locally

    git rm --cached path/to/file

    Then add it to .gitignore.

The calculation happens instantly in your browser. The numbers you enter are not sent to our servers or saved.

How to use the Git Command Helper

  1. Type what you want to do, or pick a category.
  2. Read the command and the note about when to use it.
  3. Copy the command into your terminal.

What does this tool do?

Git has hundreds of commands and options, but most days you need a few dozen. This helper covers everyday work, branching, undoing mistakes, stashing, history, remotes and tags.

Each recipe says when it's safe — for example, amending and resetting rewrite history, so use them only on commits you haven't pushed.

Why use it?

  • Search in plain English.
  • Safety notes on risky commands.
  • One-click copy.

Privacy

The calculation happens instantly in your browser. The numbers you enter are not sent to our servers or saved. There's no account to create and nothing to install.

Last reviewed by the M2Toolkit team.

Other tools people use alongside the git command helper.