Skip to content

Git Command Generator

Pick what you want to do and fill in your branch or file names. You get the exact commands to run, what they do, and a warning when a command rewrites history or deletes work.

Set your name and email

Commands
git config --global user.name "Ada Lovelace"
git config --global user.email [email protected]

Sets the author shown on every commit you make on this computer. Leave out --global to set it for the current repository only.

Last reviewed:

What is Git?

Git is the distributed version control system used by almost every software team. A repository stores the complete history of a project as a chain of commits, each a snapshot of the files with an author, date, message and a pointer to its parent. Branches are lightweight movable labels pointing at commits, which lets you work on several lines of development at once and combine them with merges or rebases. Every clone holds the full history, and push, pull and fetch exchange commits with remotes such as GitHub or GitLab.

Git is powerful but its commands are notoriously hard to remember. The same verb does different things depending on its flags (git reset --soft keeps your changes; git reset --hard deletes them), common tasks need several commands in the right order, and a few commands rewrite history in ways that cause trouble for teammates. Newer commands such as git switch and git restore, added in Git 2.23 in 2019, split up the overloaded git checkout, but many guides still use the older forms.

This generator collects 29 everyday tasks in six groups: setup, branches, commits, working files, history, and tags and remotes. For each one you fill in names, and it gives you the exact commands, an explanation of what they do, and a clear warning if they rewrite history or delete work.

How to use this tool

  1. Find your task in the list on the left, grouped under Setup, Branches, Commits, Working files, History and Tags & remotes. Type in the search box to filter by words such as "undo", "tag" or "stash".
  2. Click a task. Its fields appear with example values filled in. Replace them with your branch names, file paths, commit hashes or messages. Some tasks have checkboxes, such as also renaming a branch on the remote.
  3. The commands update as you type. Values containing spaces or shell characters are quoted for you.
  4. Read the explanation below the commands, and the warning box if one appears. Warnings mark commands that rewrite shared history or destroy uncommitted work.
  5. Click Copy and run the commands in a terminal inside your repository. Lines starting with # are comments that explain the next step.

Examples

Squash the last three commits into one

With How many commits set to 3 and the message "Add login page":

git reset --soft HEAD~3
git commit -m "Add login page"

--soft moves the branch back three commits but leaves all their changes staged, so the next commit contains everything. The tool warns that this rewrites history: if those commits were already pushed, you will need git push --force-with-lease.

Rename a branch locally and on the remote

Renaming feature/logn to feature/login with Also rename on origin ticked:

git branch -m feature/logn feature/login
git push -u origin feature/login
git push origin --delete feature/logn

Remotes have no rename operation, so the new name is pushed and the old one deleted. Teammates who checked out the old branch need to switch to the new one.

Stop tracking a file with a space in its name

For config/local settings.json:

git rm --cached "config/local settings.json"
echo "config/local settings.json" >> .gitignore
git commit -m "Stop tracking config/local settings.json"

The path is quoted because of the space. --cached removes the file from the repository but leaves it on disk.

Common errors and how to fix them

  • "Updates were rejected because the tip of your current branch is behind". The remote has commits you do not have. Run git pull --rebase (or the "Update my branch" task) and push again. Only use a force push if you rewrote your own branch on purpose.
  • "error: The branch 'x' is not fully merged". git branch -d protects unmerged work. Check the branch with git log main..x first, then use -D if you really want to delete it.
  • "fatal: refusing to merge unrelated histories". The two branches share no common commit, often after creating a repository on GitHub with a README and then pushing a separate local project. Add --allow-unrelated-histories to the pull or merge once.
  • Conflicts during a rebase or merge. Edit the conflicted files, git add them, then run git rebase --continue or git commit. To give up, use git rebase --abort or git merge --abort.
  • "git switch" is not a git command. Your Git is older than 2.23. Use git checkout -b name instead of git switch -c name, or upgrade Git.
  • Lost commits after a reset. git reflog lists where your branch pointed recently. Find the hash and run git reset --hard <hash> to go back, as long as it was within the reflog's expiry period (90 days by default).

When developers use this

  • Fixing a commit message or adding a forgotten file just before pushing.
  • Cleaning up a feature branch, by squashing work-in-progress commits or rebasing on the latest main, before opening a pull request.
  • Undoing a bad commit on a shared branch safely with git revert instead of rewriting history.
  • Tracking down which commit introduced a bug with git bisect.
  • Removing an accidentally committed .env file from tracking, and remembering to rotate the secret.
  • Onboarding: setting name and email, cloning, and publishing a first project.

Privacy and how it works

The commands are built from text templates in your browser. Nothing you type, including repository URLs, branch names and commit messages, is sent anywhere, and the tool never connects to your repositories. You run the commands yourself, so you stay in control of what happens.

Limitations

  • Commands are written for a Bash-like shell. In PowerShell or cmd.exe most work unchanged, but quoting and the echo … >> .gitignore line can behave differently.
  • The tool does not know the state of your repository. Check git status before running destructive commands.
  • The remote is assumed to be called origin. Replace it if yours has a different name.

FAQ

What is the difference between git reset --soft, --mixed and --hard?

All three move the branch back. --soft keeps the undone changes staged, --mixed (the default) keeps them as unstaged changes, and --hard discards them. Only --hard loses work, and uncommitted changes lost that way cannot be recovered.

When should I use revert instead of reset?

Use git revert for commits that are already pushed to a shared branch. It adds a new commit that undoes the old one, so nobody's history breaks. Use reset only for local commits nobody else has.

Why --force-with-lease instead of --force?

--force-with-lease refuses to overwrite the remote branch if it has commits you have not fetched, such as a teammate's push. Plain --force overwrites them silently.

Should I merge or rebase to update my branch?

Rebasing gives a straight, readable history, but it rewrites your branch's commits, so only rebase branches you own. Merging never rewrites history and is safer on shared branches, at the cost of extra merge commits. Many teams rebase feature branches and merge into main.

Does removing a file from Git delete it from history?

No. git rm --cached only stops tracking it from now on; it stays in older commits. To purge it from history, use a tool such as git filter-repo, and treat any leaked secret as compromised.

How does git bisect find the bad commit so quickly?

It performs a binary search. You mark one good and one bad commit, Git checks out the commit halfway between, and you mark it good or bad, halving the range each time. About 10 steps cover 1,000 commits.

Why are tags not pushed with git push?

By default git push sends branches only. Push a tag explicitly with git push origin <tag>, as the release tag task does, or all tags at once with git push --tags.

Guides