Skip to content
koducathome

Git Command Helper

Describe what you want to do and find the Git command for it, with an explanation and a warning when the command rewrites history.

How to use this tool

Steps for using the Git Command Helper.

  1. Describe what you want to do in the search box — for example *undo last commit*, *rename branch* or *recover deleted branch*. Results update as you type.
  2. Narrow the list with a category chip: setup, branching, committing, undoing, history, remote, stash, rebase & merge, tags, cleanup or recovery.
  3. Read the explanation on the card, and pay attention to any Careful warning — it marks commands that rewrite history or discard work.
  4. Fill in placeholders such as <branch> or <commit> in the small inputs on the card. The command updates live; branch and tag names are checked against Git's naming rules and values are shell-quoted when needed.
  5. Click Copy next to a command and run it in your terminal.

Example

Search for a task

Search
undo last commit
Top results
Undo the last commit but keep the changes staged
  git reset --soft HEAD~1
Undo the last commit and unstage its changes
  git reset HEAD~1
Delete the last commit and its changes
  git reset --hard HEAD~1

Common use cases

  • Undoing a commit or a git add without losing work.
  • Looking up the exact syntax for rarely used commands like git bisect, git remote set-url or git push origin --delete.
  • Recovering a branch or commit after a bad reset or rebase.
  • Teaching Git to new team members with explanations and clear warnings.
  • Cleaning up merged branches, stale remote-tracking refs and untracked build artefacts.
  • Comparing changes before committing, alongside the Text Diff tool for arbitrary snippets.

Choosing the right Git command

Git has several commands that look similar but behave very differently, and the right choice usually depends on one question: have the commits been pushed? Commands like git commit --amend, git reset, git rebase and squashing rewrite commits — they create new commit IDs. That is harmless on a private branch but causes diverged histories for anyone who already pulled the old commits. For commits on a shared branch, git revert is the safe way to undo, because it adds a new commit instead of removing old ones.

Modern Git (2.23+) split the overloaded git checkout into two clearer commands: git switch changes branches (git switch -c creates one) and git restore changes files (git restore --staged unstages, git restore <file> discards edits). The catalog uses these where they apply, and mentions the older equivalents in the explanations so you recognise them in existing documentation.

The three modes of git reset are a frequent source of lost work. --soft moves the branch but keeps changes staged, the default --mixed keeps them unstaged in your working tree, and --hard discards them. Committed work is rarely truly lost: the reflog records every position HEAD has had for about 90 days, so git reflog followed by git switch -c <new-branch> <commit> or git reset --hard HEAD@{1} can recover from most mistakes. Uncommitted changes and untracked files deleted by git clean are not recorded anywhere, which is why those entries carry a warning.

When you must overwrite a remote branch after rewriting history, use git push --force-with-lease rather than --force: it refuses to push if the remote has commits you have not seen, so you cannot silently delete a colleague's work. Placeholders filled in on this page are validated — branch and tag names follow the rules of git check-ref-format (no spaces, no .., no leading -, no ~ ^ : ? * [ \, no .lock suffix) — and any value with special characters is wrapped in single quotes so it is passed to Git as one argument.

Limitations

  • The catalog is curated (about 60 tasks) rather than a full Git reference; see git help <command> for every option.
  • Commands target Git 2.23 or newer (git switch, git restore); git init -b needs 2.28+.
  • Shell quoting follows POSIX shells (bash, zsh). In Windows cmd.exe, use double quotes instead of single quotes.
  • The tool never runs commands; it only shows them.

Frequently asked questions

How do I undo the last commit but keep my changes?

Run git reset --soft HEAD~1 to keep the changes staged, or git reset HEAD~1 to keep them unstaged. If the commit was already pushed to a shared branch, use git revert <commit> instead.

What is the difference between git reset and git revert?

git reset moves the branch pointer backwards, removing commits from the branch history. git revert creates a new commit that undoes an earlier one, leaving history intact — the safe choice for commits others already have.

Is git push --force dangerous?

Yes, on shared branches: it replaces the remote history with yours. Prefer git push --force-with-lease, which fails if someone else pushed in the meantime, and avoid force-pushing to main without agreement.

Can I recover a deleted branch?

Usually. git branch -D prints the commit hash it deleted, and git reflog lists recent HEAD positions. Recreate the branch with git branch <branch> <commit>.

Why is my branch name rejected?

Git reference names cannot contain spaces, .., ~, ^, :, ?, *, [, backslashes or control characters, cannot start with - or ., and cannot end with /, . or .lock. Use hyphens or slashes instead, e.g. feature/new-login.