Git Command Generator
Search and copy git commands โ filter by category, find by keyword.
Create a new empty Git repository in the current directory.
git initDownload a remote repository to a local directory.
git clone <url>Clone with only the latest commit โ much faster for large repos.
git clone --depth 1 <url>Set the name that will appear in all your commits.
git config --global user.name "Your Name"Set the email that will appear in all your commits.
git config --global user.email "you@example.com"Show all current Git configuration settings.
git config --listChange the editor used for commit messages (e.g., VS Code).
git config --global core.editor "code --wait"Show all local branches. Add -a to include remote branches.
git branchShow local and remote tracking branches.
git branch -aCreate a new branch without switching to it.
git branch <branch-name>Switch to an existing branch.
git switch <branch-name>Create a new branch and switch to it in one step.
git switch -c <branch-name>Rename the current branch.
git branch -m <new-name>Delete a branch that has already been merged.
git branch -d <branch-name>Force-delete a branch even if it has unmerged changes.
Permanently deletes local changes on the branch if unmerged.
git branch -D <branch-name>Merge another branch into the current branch.
git merge <branch-name>Merge with a merge commit even if fast-forward is possible โ preserves branch history.
git merge --no-ff <branch-name>Replay your commits on top of another branch for a linear history.
Rewrites commit history. Never rebase shared/published branches.
git rebase <branch-name>Squash, reorder, or edit the last N commits interactively.
Rewrites commit history. Avoid on branches others have pulled.
git rebase -i HEAD~<n>Show the working tree status โ modified, staged, and untracked files.
git statusStage all modified and new files for the next commit.
git add .Stage a specific file for the next commit.
git add <file>Interactively select hunks within files to stage โ great for partial commits.
git add -pShow changes in the working tree that are not yet staged.
git diffShow changes that are staged and ready to commit.
git diff --stagedDiscard unstaged changes in a file, restoring it to the last commit.
Permanently discards uncommitted changes in that file.
git restore <file>Remove a file from the staging area without discarding its changes.
git restore --staged <file>Create a commit with a message from all staged changes.
git commit -m "your message"Stage all changes to tracked files and commit in one step.
git commit -am "your message"Change the message of the most recent commit.
Rewrites the last commit. Don't amend commits already pushed.
git commit --amendAdd staged changes to the last commit without changing its message.
Rewrites the last commit. Don't amend commits already pushed.
git commit --amend --no-editConnect the local repo to a remote repository URL.
git remote add origin <url>Show all configured remote connections and their URLs.
git remote -vDownload changes from remote without merging into local branches.
git fetchFetch and merge changes from the remote tracking branch.
git pullFetch remote changes and rebase your local commits on top โ keeps history linear.
git pull --rebaseUpload local commits to the remote branch.
git push origin <branch-name>Push and set the remote as the default tracking branch for future pulls.
git push -u origin <branch-name>Force push only if nobody else has pushed since your last fetch โ safer than --force.
Still overwrites remote history. Only use on your own feature branches.
git push --force-with-leaseCreate a new commit that undoes the changes of a previous commit โ safe for shared branches.
git revert <commit-hash>Move HEAD back one commit, keeping changes staged. Use to re-commit with a different message.
Rewrites history. Don't use on pushed commits.
git reset --soft HEAD~1Move HEAD back one commit and unstage changes, but keep your file edits.
Rewrites history. Don't use on pushed commits.
git reset HEAD~1Move HEAD back one commit and permanently discard all changes.
DESTRUCTIVE โ permanently deletes uncommitted changes and the last commit.
git reset --hard HEAD~1Delete untracked files and directories from the working tree.
DESTRUCTIVE โ permanently deletes files not tracked by Git.
git clean -fdList commits with author, date, and full message.
git logShow each commit on a single line โ short hash and subject.
git log --onelineShow commit history as a visual ASCII graph with all branches.
git log --oneline --graph --allDisplay the diff and metadata for a specific commit.
git show <commit-hash>Show which commit and author last modified each line of a file.
git blame <file>Show the commit history for a specific file.
git log --follow -p <file>Show differences between two commits or branches.
git diff <commit-a>..<commit-b>Show all tags in the repository.
git tagCreate a lightweight tag pointing to the current commit.
git tag <tag-name>Create an annotated tag with a message โ recommended for releases.
git tag -a <tag-name> -m "Release message"Push all local tags to the remote.
git push origin --tagsRemove a tag from the local repository.
git tag -d <tag-name>Remove a tag that was already pushed to the remote.
git push origin --delete <tag-name>Save uncommitted changes to a temporary shelf so you can switch branches.
git stashStash changes with a descriptive name for easier identification later.
git stash push -m "stash description"Apply the most recent stash and remove it from the stash list.
git stash popShow all stashed changes.
git stash listApply a specific stash without removing it from the list.
git stash apply stash@{<n>}Remove a specific stash entry without applying it.
git stash drop stash@{<n>}Apply changes from a specific commit onto the current branch.
git cherry-pick <commit-hash>Show a log of all HEAD movements โ useful for recovering 'lost' commits after reset.
git reflogBegin a binary search to find which commit introduced a bug.
git bisect startShow commit counts grouped by author โ useful for changelogs.
git shortlog -snCheck out a branch into a separate directory โ work on two branches simultaneously.
git worktree add ../<dir> <branch-name>Include another Git repository as a subdirectory of your project.
git submodule add <url> <path>Create a zip/tar archive of the repo at a specific commit without .git history.
git archive --format=zip HEAD > repo.zipShow the hooks available in the .git/hooks directory.
ls .git/hooks71 commands
About this tool
The Git Command Generator is a searchable reference for 60+ git commands organized by category โ Setup, Branches, Staging, Commits, Remote, Undo, History, Tags, Stash, and Advanced. Search by name or keyword to find the exact command, copy it with one click, and see warning badges on destructive commands that rewrite history.
When to use it
- โQuickly finding the right git syntax without leaving the browser
- โLearning git commands beyond the basics (reflog, bisect, worktree)
- โChecking the correct flags for destructive operations before running them
- โOnboarding new developers to git workflows with a visual reference
Tips
- โCommands marked with a Caution badge rewrite history โ never use them on branches others have already pulled.
- โSearch by concept, not just command name: try 'undo', 'linear', or 'recover' to find commands by what they do.
- โYour recently copied commands are saved in localStorage for quick re-access.
Frequently asked questions
What is the difference between git reset and git revert?
git revert creates a new commit that undoes a previous commit โ it's safe to use on shared branches because it doesn't rewrite history. git reset moves the HEAD pointer backward, effectively removing commits from the history โ this rewrites history and is destructive. Only use git reset on commits that haven't been pushed to a shared branch.
When should I use git rebase instead of git merge?
Use rebase when you want a linear, clean commit history โ your commits are replayed on top of the target branch as if they were written there. Use merge when you want to preserve the true divergence history with a merge commit. The golden rule: never rebase branches that others have already pulled from, as it rewrites the commit hashes they reference.
What does git stash do and when should I use it?
git stash temporarily saves your uncommitted changes (both staged and unstaged) to a stack, leaving your working directory clean. Use it when you need to quickly switch branches or pull changes without committing half-finished work. Run git stash pop to restore the most recent stash, or git stash list to see all stored stashes.
How do I recover commits after a git reset --hard?
Use git reflog โ it logs every position HEAD has been at, even after hard resets. Find the commit hash you want to recover in the reflog output, then run git checkout <hash> to inspect it, or git reset --hard <hash> to restore your branch to that state. The reflog is local and expires after 90 days by default.