Git Command Builder

Pick what you need to do, fill in the parameters and get the exact sequence of Git commands, with an explanation and a warning for operations that rewrite history.

Operation

Parameters

Command

git reset --soft HEAD~1

Moves HEAD back while keeping the changes staged, ready for a new commit.

Use via API

The Git Command Builder only assembles text from templates, with no processing that would justify an endpoint. The generated commands run in your terminal, not on a server.

How to use

  1. Choose the operation from the list.
  2. Fill in the parameters (branch, commit, message).
  3. Read the explanation and risk warnings.
  4. Copy the commands and run them in your terminal.

Use cases

  • Undoing a commit made on the wrong branch.
  • Cleaning up history before opening a pull request.
  • Renaming local and remote branches without missing a step.
  • Removing a file from the repository that should have been in .gitignore.

Technical concepts

reset --soft, --mixed and --hard

All three move HEAD. --soft keeps the changes staged, --mixed (the default) keeps them in the working tree unstaged and --hard discards everything. Discarded commits can still be recovered with git reflog for a while.

Rewriting history

amend, reset and rebase create new commits with new hashes. On branches that were already pushed, this requires a force push and breaks the history for anyone who pulled it. Prefer git revert on shared branches and --force-with-lease over --force.

switch and restore

Since Git 2.23, git switch changes branches and git restore restores files, splitting the responsibilities of the old git checkout and reducing mistakes.

Frequently asked questions

How do I recover a commit lost after reset --hard?

Run git reflog, find the hash from before the reset and use git reset --hard <hash> or create a branch from it.

What is the difference between --force and --force-with-lease?

--force overwrites the remote unconditionally. --force-with-lease refuses the push if someone pushed commits you do not have locally yet.

Related tools