Git Command Generator
Build Git commands visually — pick an operation, fill in the parameters, copy the command
Operations
git init
Initialize a new Git repository
Parameters
Leave blank to initialize in the current directory
Requires Git 2.28+. Leave blank to use Git's default (usually 'master')
What this does
Initializes a new, empty Git repository in the current directory. Creates a hidden .git folder with all the metadata Git needs to track changes.
Quick reference — common workflows▼
Start a new feature
Undo last commit (keep changes)
Sync with upstream
Save & restore WIP
You need to cherry-pick a commit from another branch, but you can’t remember whether it’s git cherry-pick <hash> or git cherry-pick <branch> <hash>. Or you’re writing a script that does git stash push -m "message" -- file1 file2 and the flag order is wrong. Or someone asks you to squash the last 3 commits and you mix up git rebase -i HEAD~3 with git reset --soft HEAD~3. Git has 150+ commands with hundreds of flags — nobody memorizes them all.
Why This Generator (Not the Git Branch Name Generator)
PureDevTools has a Git Branch Name Generator for converting task descriptions into valid branch names. This tool is for building Git commands — pick an operation from 7 categories (basic, branching, remote, history, stashing, submodules, advanced), fill in the parameters, and get the exact command with a plain-English explanation. Everything runs in your browser; no data is sent anywhere.
What Is a Git Command Generator?
A Git command generator is a visual alternative to memorizing Git syntax. Instead of recalling whether the flag is -b or -c, or how to format a git reset with a commit reference, you choose the operation from a menu, fill in the relevant fields, and the tool assembles the correct command for you.
This generator covers 7 categories of Git operations:
- Repository Setup —
git initandgit clone - Branching — create, switch, delete, list, and rename branches
- Committing — stage changes, commit, and amend the last commit
- Remote — push, pull, fetch, and add remotes
- Stashing — save, apply, list, and drop stashes
- History —
git log,git diff,git blame, andgit show - Undoing —
git reset,git revert, restore files, andgit clean
Every generated command comes with a plain-English explanation of exactly what it will do, so you learn Git patterns as you use the tool.
Git Fundamentals
The Three-State Model
Git tracks your files through three states:
- Working tree — files on disk as you see them in your editor
- Staging area (index) — a snapshot prepared for the next commit (
git addmoves changes here) - Repository — the committed history stored in the
.gitfolder
Understanding this model explains most Git commands:
git addmoves changes from working tree → staging areagit commitmoves the staging area snapshot → repositorygit restoremoves content from staging area → working tree (discards edits)git reset --softmoves HEAD back in the repository while leaving staging and working tree intact
Commits Are Snapshots, Not Diffs
Git stores each commit as a complete snapshot of your project at that point in time, not just the changed lines. What looks like a “diff” in git log -p is computed on the fly by comparing two snapshots. This makes operations like git checkout and git revert fast and reliable.
HEAD, Branches, and Detached HEAD
HEAD is a pointer to the current commit. Normally it points to a branch name, which itself points to a commit. When you commit, the branch pointer moves forward.
A detached HEAD happens when HEAD points directly to a commit hash instead of a branch name — this occurs when you checkout a specific tag or hash. Any commits you make in detached HEAD state are unreachable once you switch away (unless you create a branch first).
Common Operations Explained
Branching Strategies
Creating a branch is cheap and fast in Git because branches are just 40-byte pointers:
# Create and switch to a feature branch
git switch -c feature/user-auth main
# Do your work, then push
git push -u origin feature/user-auth
Branch naming conventions:
| Prefix | Purpose | Example |
|---|---|---|
feature/ | New feature | feature/dark-mode |
fix/ | Bug fix | fix/login-crash |
hotfix/ | Urgent production fix | hotfix/xss-patch |
refactor/ | Code restructuring | refactor/auth-module |
docs/ | Documentation only | docs/api-reference |
release/ | Release preparation | release/v2.1.0 |
Undoing Changes Safely
Choosing the right undo command depends on whether your work has been shared:
| Situation | Command | Safe to use on pushed commits? |
|---|---|---|
| Undo last commit, keep changes staged | git reset --soft HEAD~1 | No |
| Undo last commit, keep changes unstaged | git reset --mixed HEAD~1 | No |
| Undo last commit and discard all changes | git reset --hard HEAD~1 | No |
| Reverse a specific commit (keeps history) | git revert <hash> | Yes |
| Discard edits to a single file | git restore <file> | — |
Rule of thumb: use git reset only for local, unpushed commits. Use git revert once commits are on a shared remote.
The Difference Between Fetch, Pull, and Push
# Only download — does NOT change your working branch
git fetch --prune origin
# Download + merge (or rebase) — updates your current branch
git pull --rebase origin main
# Upload your commits to the remote
git push origin main
git fetch is the safest way to check what teammates have pushed before deciding whether to merge or rebase. It updates remote-tracking branches (origin/main) without touching your local main.
Stashing: Save Your WIP
Stashing is useful when you need to switch contexts quickly:
# Save current work
git stash push -u -m "WIP: half-done refactor"
# Switch to another branch to fix a bug
git switch hotfix/urgent-fix
# ... fix the bug, commit, push ...
# Come back and restore your WIP
git switch feature/my-feature
git stash pop
git stash list shows all saved stashes with their index numbers. git stash pop stash@{2} applies a specific one.
Shallow Clones for Speed
When you only need the latest code (e.g. in CI/CD pipelines), a shallow clone dramatically reduces download time:
git clone --depth 1 https://github.com/user/repo.git
This fetches only the most recent commit without the full history. You can deepen the clone later with git fetch --unshallow.
Understanding git log Formats
The git log command has many useful output formats:
# Compact one-liner per commit
git log --oneline
# Visual branch/merge graph
git log --oneline --graph --decorate
# Filter by author
git log --author="Alice" --oneline
# Show only commits touching a specific file
git log --oneline -- src/auth.ts
# Show the last 10 commits
git log -n 10 --oneline
Git Aliases — Speed Up Your Workflow
Once you know the commands, aliases save time. Add these to your ~/.gitconfig:
[alias]
st = status
co = checkout
sw = switch
br = branch
ci = commit
lg = log --oneline --graph --decorate --all
unstage = restore --staged
undo = reset --soft HEAD~1
Frequently Asked Questions
What is the difference between git merge and git rebase?
git merge creates a merge commit that joins two branch histories. The result clearly shows when branches diverged and were combined. git rebase replays your commits on top of the target branch, creating a linear history as if you had started work from the latest commit. Rebase makes history cleaner but rewrites commit hashes — avoid rebasing branches that others are working on.
How do I see what changed in the last commit?
git show
This shows the commit metadata and the full diff. Use git show HEAD~1 to see the commit before that, or git show abc1234 for a specific hash.
How do I rename a remote branch?
Git has no direct “rename remote branch” command. The workflow is:
# 1. Rename locally
git branch -m old-name new-name
# 2. Push the new name
git push origin new-name
# 3. Delete the old remote branch
git push origin --delete old-name
How do I list all branches including remote?
git branch -a
What does git clean do and is it safe?
git clean removes untracked files (files Git doesn’t know about) from your working tree. It is irreversible — unlike changes to tracked files, untracked files are not stored anywhere in Git. Always run with -n (dry run) first:
git clean -n # preview what would be deleted
git clean -fd # actually delete files and directories
Does this tool store my branch names or commit messages?
No. All processing happens entirely in your browser. Nothing you type — branch names, remote URLs, commit messages, or any other input — is transmitted to or stored on any server.