Git Command Generator
Search commands, build complex operations, and follow workflow templates. Click any command to copy.
Setup
(5)git init Initialize a new Git repository in the current directory
git initgit clone <url> Clone a remote repository to your local machine
git clone https://github.com/user/repo.gitgit config --global user.name "<name>" Set your name for all repositories
git config --global user.name "Jane Doe"git config --global user.email "<email>" Set your email for all repositories
git config --global user.email "[email protected]"git config --list Show all Git configuration settings
git config --listBasics
(8)git status Show the status of your working directory and staging area
git statusgit add <file> Stage a specific file for commit
git add src/app.jsgit add . Stage all changes in the current directory
git add .git add -p Interactively stage hunks of changes
git add -pgit commit -m "<message>" Commit staged changes with a message
git commit -m "Add login feature"git commit --amend Modify the last commit (message or staged files)
git commit --amend -m "Updated message"git rm <file> Remove a file from the working tree and stage the deletion
git rm old-file.txtgit mv <old> <new> Rename or move a file and stage the change
git mv old-name.js new-name.jsBranching
(9)git branch List all local branches
git branchgit branch -a List all local and remote branches
git branch -agit branch <name> Create a new branch (does not switch to it)
git branch feature/logingit checkout -b <name> Create a new branch and switch to it
git checkout -b feature/logingit switch <name> Switch to an existing branch
git switch maingit switch -c <name> Create and switch to a new branch (modern syntax)
git switch -c feature/logingit branch -d <name> Delete a branch (safe, prevents deleting unmerged)
git branch -d feature/logingit branch -D <name> Force delete a branch even if unmerged
git branch -D feature/logingit branch -m <old> <new> Rename a branch
git branch -m old-name new-nameMerging
(8)git merge <branch> Merge a branch into the current branch
git merge feature/logingit merge --no-ff <branch> Merge with a merge commit even if fast-forward is possible
git merge --no-ff feature/logingit merge --squash <branch> Squash all commits from branch into a single staged change
git merge --squash feature/logingit merge --abort Abort a merge in progress and return to pre-merge state
git merge --abortgit rebase <branch> Rebase current branch onto another branch
git rebase maingit rebase -i HEAD~<n> Interactive rebase to edit, squash, or reorder last N commits
git rebase -i HEAD~3git rebase --abort Abort a rebase in progress
git rebase --abortgit rebase --continue Continue a rebase after resolving conflicts
git rebase --continueRemote
(10)git remote -v List all configured remote repositories
git remote -vgit remote add <name> <url> Add a new remote repository
git remote add origin https://github.com/user/repo.gitgit remote remove <name> Remove a remote
git remote remove origingit push <remote> <branch> Push a branch to a remote repository
git push origin maingit push -u <remote> <branch> Push and set the upstream tracking branch
git push -u origin feature/logingit push --force Force push, overwriting remote history (use with caution)
git push --force origin feature/logingit pull <remote> <branch> Fetch and merge changes from a remote branch
git pull origin maingit pull --rebase Fetch and rebase instead of merging
git pull --rebase origin maingit fetch <remote> Download objects and refs from remote without merging
git fetch origingit fetch --prune Fetch and remove refs to deleted remote branches
git fetch --prune originStashing
(8)git stash Stash uncommitted changes for later
git stashgit stash push -m "<message>" Stash with a descriptive message
git stash push -m "WIP: login form"git stash list List all stashes
git stash listgit stash pop Apply the most recent stash and remove it from the list
git stash popgit stash apply Apply the most recent stash but keep it in the list
git stash applygit stash drop Delete the most recent stash
git stash dropgit stash drop stash@{<n>} Delete a specific stash by index
git stash drop stash@{2}git stash clear Delete all stashes
git stash clearHistory
(12)git log Show commit history
git loggit log --oneline Show compact commit history (one line per commit)
git log --onelinegit log --oneline --graph Show commit history as a graph
git log --oneline --graph --allgit log -n <number> Show only the last N commits
git log -n 5git log --author="<name>" Show commits by a specific author
git log --author="Jane"git log -- <file> Show commit history for a specific file
git log -- src/app.jsgit diff Show unstaged changes in the working directory
git diffgit diff --staged Show staged changes (ready to commit)
git diff --stagedgit diff <branch1> <branch2> Compare two branches
git diff main feature/logingit blame <file> Show who last modified each line of a file
git blame src/app.jsgit show <commit> Show details and diff for a specific commit
git show abc1234git reflog Show a log of all reference changes (useful for recovery)
git reflogUndoing Changes
(10)git restore <file> Discard changes in working directory (restore from staging)
git restore src/app.jsgit restore --staged <file> Unstage a file (keep working directory changes)
git restore --staged src/app.jsgit reset --soft HEAD~1 Undo last commit, keep changes staged
git reset --soft HEAD~1git reset HEAD~1 Undo last commit, unstage changes (keep in working dir)
git reset HEAD~1git reset --hard HEAD~1 Undo last commit and discard all changes permanently
git reset --hard HEAD~1git reset --hard <commit> Reset branch to a specific commit, discard everything after
git reset --hard abc1234git revert <commit> Create a new commit that undoes a specific commit
git revert abc1234git cherry-pick <commit> Apply a specific commit from another branch
git cherry-pick abc1234git cherry-pick -n <commit> Apply commit changes without auto-committing
git cherry-pick -n abc1234git clean -fd Remove untracked files and directories
git clean -fdTags
(8)git tag List all tags
git taggit tag <name> Create a lightweight tag at the current commit
git tag v1.0.0git tag -a <name> -m "<message>" Create an annotated tag with a message
git tag -a v1.0.0 -m "Release 1.0.0"git tag -a <name> <commit> Tag a specific commit
git tag -a v1.0.0 abc1234git push <remote> <tag> Push a specific tag to remote
git push origin v1.0.0git push <remote> --tags Push all tags to remote
git push origin --tagsgit tag -d <name> Delete a local tag
git tag -d v1.0.0git push <remote> :refs/tags/<name> Delete a remote tag
git push origin :refs/tags/v1.0.0Advanced
(10)git bisect start Start a binary search to find a commit that introduced a bug
git bisect startgit bisect bad Mark the current commit as bad (has bug)
git bisect badgit bisect good <commit> Mark a known good commit
git bisect good abc1234git bisect reset End bisect session and return to original branch
git bisect resetgit worktree add <path> <branch> Create a linked working tree for a branch
git worktree add ../hotfix hotfix/urgentgit submodule add <url> Add a Git submodule to the repository
git submodule add https://github.com/lib/util.gitgit submodule update --init --recursive Initialize and update all submodules
git submodule update --init --recursivegit shortlog -sn Show commit count per author, sorted
git shortlog -sngit log --all --oneline --graph --decorate Visual branch graph with decorations
git log --all --oneline --graph --decorategit archive --format=zip HEAD -o repo.zip Create a zip archive of the current HEAD
git archive --format=zip HEAD -o repo.zip