Git Command Generator

Search and copy git commands โ€” filter by category, find by keyword.

1
Initialize repoSetup

Create a new empty Git repository in the current directory.

git init
2
Clone repositorySetup

Download a remote repository to a local directory.

git clone <url>
3
Shallow cloneSetup

Clone with only the latest commit โ€” much faster for large repos.

git clone --depth 1 <url>
4
Set global usernameSetup

Set the name that will appear in all your commits.

git config --global user.name "Your Name"
5
Set global emailSetup

Set the email that will appear in all your commits.

git config --global user.email "you@example.com"
6
List configSetup

Show all current Git configuration settings.

git config --list
7
Set default editorSetup

Change the editor used for commit messages (e.g., VS Code).

git config --global core.editor "code --wait"
8
List branchesBranches

Show all local branches. Add -a to include remote branches.

git branch
9
List all branchesBranches

Show local and remote tracking branches.

git branch -a
10
Create branchBranches

Create a new branch without switching to it.

git branch <branch-name>
11
Switch branchBranches

Switch to an existing branch.

git switch <branch-name>
12
Create & switch branchBranches

Create a new branch and switch to it in one step.

git switch -c <branch-name>
13
Rename branchBranches

Rename the current branch.

git branch -m <new-name>
14
Delete merged branchBranches

Delete a branch that has already been merged.

git branch -d <branch-name>
15
Force delete branchBranchesCaution

Force-delete a branch even if it has unmerged changes.

Permanently deletes local changes on the branch if unmerged.

git branch -D <branch-name>
16
Merge branchBranches

Merge another branch into the current branch.

git merge <branch-name>
17
Merge (no fast-forward)Branches

Merge with a merge commit even if fast-forward is possible โ€” preserves branch history.

git merge --no-ff <branch-name>
18
Rebase onto branchBranchesCaution

Replay your commits on top of another branch for a linear history.

Rewrites commit history. Never rebase shared/published branches.

git rebase <branch-name>
19
Interactive rebaseBranchesCaution

Squash, reorder, or edit the last N commits interactively.

Rewrites commit history. Avoid on branches others have pulled.

git rebase -i HEAD~<n>
20
Show statusStaging

Show the working tree status โ€” modified, staged, and untracked files.

git status
21
Stage all changesStaging

Stage all modified and new files for the next commit.

git add .
22
Stage a fileStaging

Stage a specific file for the next commit.

git add <file>
23
Stage interactively (patch)Staging

Interactively select hunks within files to stage โ€” great for partial commits.

git add -p
24
Show unstaged diffStaging

Show changes in the working tree that are not yet staged.

git diff
25
Show staged diffStaging

Show changes that are staged and ready to commit.

git diff --staged
26
Discard file changesStagingCaution

Discard unstaged changes in a file, restoring it to the last commit.

Permanently discards uncommitted changes in that file.

git restore <file>
27
Unstage a fileStaging

Remove a file from the staging area without discarding its changes.

git restore --staged <file>
28
Commit staged changesCommits

Create a commit with a message from all staged changes.

git commit -m "your message"
29
Stage & commit tracked filesCommits

Stage all changes to tracked files and commit in one step.

git commit -am "your message"
30
Amend last commit messageCommitsCaution

Change the message of the most recent commit.

Rewrites the last commit. Don't amend commits already pushed.

git commit --amend
31
Amend last commit (keep message)CommitsCaution

Add staged changes to the last commit without changing its message.

Rewrites the last commit. Don't amend commits already pushed.

git commit --amend --no-edit
32
Add remote originRemote

Connect the local repo to a remote repository URL.

git remote add origin <url>
33
List remotesRemote

Show all configured remote connections and their URLs.

git remote -v
34
Fetch from remoteRemote

Download changes from remote without merging into local branches.

git fetch
35
Pull changesRemote

Fetch and merge changes from the remote tracking branch.

git pull
36
Pull with rebaseRemote

Fetch remote changes and rebase your local commits on top โ€” keeps history linear.

git pull --rebase
37
Push to remoteRemote

Upload local commits to the remote branch.

git push origin <branch-name>
38
Push & set upstreamRemote

Push and set the remote as the default tracking branch for future pulls.

git push -u origin <branch-name>
39
Force push (safe)RemoteCaution

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-lease
40
Revert a commitUndo

Create a new commit that undoes the changes of a previous commit โ€” safe for shared branches.

git revert <commit-hash>
41
Reset (soft) โ€” undo commit, keep stagedUndoCaution

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~1
42
Reset (mixed) โ€” undo commit, keep filesUndoCaution

Move HEAD back one commit and unstage changes, but keep your file edits.

Rewrites history. Don't use on pushed commits.

git reset HEAD~1
43
Reset (hard) โ€” discard everythingUndoCaution

Move HEAD back one commit and permanently discard all changes.

DESTRUCTIVE โ€” permanently deletes uncommitted changes and the last commit.

git reset --hard HEAD~1
44
Remove untracked filesUndoCaution

Delete untracked files and directories from the working tree.

DESTRUCTIVE โ€” permanently deletes files not tracked by Git.

git clean -fd
45
Show commit logHistory

List commits with author, date, and full message.

git log
46
Show compact logHistory

Show each commit on a single line โ€” short hash and subject.

git log --oneline
47
Show branch graphHistory

Show commit history as a visual ASCII graph with all branches.

git log --oneline --graph --all
48
Show a commitHistory

Display the diff and metadata for a specific commit.

git show <commit-hash>
49
Blame a fileHistory

Show which commit and author last modified each line of a file.

git blame <file>
50
File historyHistory

Show the commit history for a specific file.

git log --follow -p <file>
51
Diff between commitsHistory

Show differences between two commits or branches.

git diff <commit-a>..<commit-b>
52
List tagsTags

Show all tags in the repository.

git tag
53
Create lightweight tagTags

Create a lightweight tag pointing to the current commit.

git tag <tag-name>
54
Create annotated tagTags

Create an annotated tag with a message โ€” recommended for releases.

git tag -a <tag-name> -m "Release message"
55
Push all tagsTags

Push all local tags to the remote.

git push origin --tags
56
Delete local tagTags

Remove a tag from the local repository.

git tag -d <tag-name>
57
Delete remote tagTags

Remove a tag that was already pushed to the remote.

git push origin --delete <tag-name>
58
Stash changesStash

Save uncommitted changes to a temporary shelf so you can switch branches.

git stash
59
Stash with messageStash

Stash changes with a descriptive name for easier identification later.

git stash push -m "stash description"
60
Pop latest stashStash

Apply the most recent stash and remove it from the stash list.

git stash pop
61
List stashesStash

Show all stashed changes.

git stash list
62
Apply stash (keep it)Stash

Apply a specific stash without removing it from the list.

git stash apply stash@{<n>}
63
Drop a stashStash

Remove a specific stash entry without applying it.

git stash drop stash@{<n>}
64
Cherry-pick commitAdvanced

Apply changes from a specific commit onto the current branch.

git cherry-pick <commit-hash>
65
Show reflogAdvanced

Show a log of all HEAD movements โ€” useful for recovering 'lost' commits after reset.

git reflog
66
Start bisectAdvanced

Begin a binary search to find which commit introduced a bug.

git bisect start
67
Contribution summaryAdvanced

Show commit counts grouped by author โ€” useful for changelogs.

git shortlog -sn
68
Add worktreeAdvanced

Check out a branch into a separate directory โ€” work on two branches simultaneously.

git worktree add ../<dir> <branch-name>
69
Add submoduleAdvanced

Include another Git repository as a subdirectory of your project.

git submodule add <url> <path>
70
Archive repositoryAdvanced

Create a zip/tar archive of the repo at a specific commit without .git history.

git archive --format=zip HEAD > repo.zip
71
List available hooksAdvanced

Show the hooks available in the .git/hooks directory.

ls .git/hooks

71 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.

Related tools

๐Ÿฅท ToolNinja