Git Command Generator

Build complex git commands visually — fill in parameters and copy.

Create & switch to branch

Create a new branch and switch to it

$ git checkout -b feature/my-feature

Delete local branch

Delete a local branch (force optional)

$ git branch -d old-branch

Delete remote branch

Delete a branch from the remote

$ git push origin --delete old-branch

Rename branch

Rename the current branch

$ git branch -m new-branch-name

List all branches

List local and remote branches

$ git branch -a

Amend last commit

Modify the last commit message

$ git commit --amend -m "Updated commit message"

Commit with message

Stage all and commit

$ git add . && git commit -m "feat: add new feature"

Squash last N commits

Squash recent commits into one

$ git reset --soft HEAD~3 && git commit -m "Combined changes"

Cherry-pick commit

Apply a specific commit to current branch

$ git cherry-pick abc1234

Undo last commit (keep changes)

Undo commit but keep files staged

$ git reset --soft HEAD~1

Undo last commit (unstage)

Undo commit and unstage files

$ git reset HEAD~1

Discard all local changes

Reset to last commit (destructive)

$ git checkout -- .

Revert a commit

Create a new commit that undoes changes

$ git revert abc1234

Unstage a file

Remove file from staging area

$ git reset HEAD src/index.ts

Add remote

Add a new remote repository

$ git remote add origin https://github.com/user/repo.git

Push with upstream

Push and set upstream tracking

$ git push -u origin main

Force push (safe)

Force push with lease (safer)

$ git push --force-with-lease origin feature-branch

Fetch and prune

Fetch remote and clean stale refs

$ git fetch --prune origin

Stash with message

Stash changes with a description

$ git stash push -m "WIP: feature work"

Apply specific stash

Apply a specific stash entry

$ git stash apply stash@\{{0}\}

List stashes

Show all stash entries

$ git stash list

Pop stash

Apply and remove the latest stash

$ git stash pop

Pretty log

One-line log with graph

$ git log --oneline --graph --decorate -n 20

Log by author

Show commits by a specific author

$ git log --author="John" --oneline -n 10

Diff between branches

Show commits in branch A not in B

$ git log main..feature --oneline

Search commit messages

Find commits by message content

$ git log --grep="fix bug" --oneline

Set user name

Set git username (global)

$ git config --global user.name "John Doe"

Set user email

Set git email (global)

$ git config --global user.email "john@example.com"

Set default branch

Set default branch name for new repos

$ git config --global init.defaultBranch main

Git Command Generator — What It Does

Browse git commands organized by category, fill in the required parameters through a simple form, and copy the exact command ready to paste into your terminal. Covers branches, commits, undo operations, stash, remotes, log, and configuration — no more hunting through man pages for the right flags.

Command Categories

  • Branch — Create, delete, rename, and switch branches
  • Commit — Amend, squash, cherry-pick, fixup commits
  • Undo — Reset (soft/mixed/hard), revert, restore, unstage
  • Remote — Push, fetch, pull, force-push with lease
  • Stash — Save, list, apply, pop, and drop stashes
  • Log — Pretty-print history, search commits, diff between refs
  • Config — Set global username, email, editor, and aliases

Essential Git Commands

  • git log --oneline --graph --all — Visual branch history
  • git diff main...feature — Changes on feature since branching from main
  • git push --force-with-lease — Safer force push (fails if remote changed)
  • git commit --amend --no-edit — Add staged changes to the last commit
  • git rebase -i HEAD~3 — Interactively squash or reorder last 3 commits

Common Mistakes to Avoid

  • git reset --hard on shared branches — Destructively discards commits; use git revert instead to preserve history.
  • Rebasing public commits — Rewriting already-pushed commits forces teammates to reset their local copies.
  • Force pushing without --force-with-lease — A plain force push can silently overwrite commits made by others since your last fetch.

Frequently Asked Questions

How do I undo the last git commit without losing my changes?
Use git reset --soft HEAD~1. The --soft flag moves the HEAD pointer back one commit but leaves your changes staged in the index. If you want changes unstaged but still in your working directory, use --mixed (the default). Use --hard only if you want to discard all changes completely.
What is the difference between git merge and git rebase?
git merge combines two branches and creates a merge commit, preserving the full history of both branches. git rebase replays your commits on top of another branch, producing a cleaner linear history. Rebase rewrites commit hashes, so never rebase commits that have already been pushed to a shared remote.
How do I delete a remote branch in Git?
Use git push origin --delete branch-name. You can also use the older syntax git push origin :branch-name. To delete the local tracking reference after that, run git fetch --prune or git branch -d branch-name for the local copy.
What does git stash do and when should I use it?
git stash saves your uncommitted changes (both staged and unstaged) to a temporary stack and reverts your working directory to the last commit. Use it when you need to quickly switch branches or pull updates without committing half-finished work. Restore with git stash pop (and remove from stack) or git stash apply (keep on stack).
How do I find which commit introduced a bug?
Use git bisect. Run git bisect start, then git bisect bad (current commit is broken) and git bisect good <known-good-commit>. Git will binary-search through history, checking out commits for you to test. Mark each as good or bad until Git identifies the first bad commit.