50+ essential Git commands organized by category. Search by what you want to do, and copy the right command with one click.
Showing 56 commands
Initialize a new Git repository
git initClone a remote repository
git clone <url>Set your name for commits
git config --global user.name "Your Name"Set your email for commits
git config --global user.email "you@example.com"List all Git configuration
git config --listShow working tree status
git statusStage a specific file
git add <file>Stage all changes
git add -ACommit staged changes with a message
git commit -m "your message"Amend the last commit (message or files)
git commit --amendShow unstaged changes
git diffShow staged changes
git diff --stagedShow commit history
git log --oneline --graphShow commit history for a specific file
git log --follow <file>List all local branches
git branchList all branches (local + remote)
git branch -aCreate a new branch
git branch <name>Switch to a branch
git checkout <branch>Create and switch to a new branch
git checkout -b <name>Delete a merged branch
git branch -d <name>Force delete an unmerged branchDestructive
git branch -D <name>Rename the current branch
git branch -m <new-name>Merge a branch into the current branch
git merge <branch>Merge with a merge commit (no fast-forward)
git merge --no-ff <branch>Abort a merge in progress
git merge --abortRebase current branch onto another
git rebase <branch>Abort a rebase in progress
git rebase --abortApply a specific commit to the current branch
git cherry-pick <commit-hash>List remote repositories
git remote -vAdd a remote repository
git remote add <name> <url>Download objects from remote (without merging)
git fetch originFetch and merge from remote
git pull origin <branch>Push commits to remote
git push origin <branch>Push and set upstream tracking branch
git push -u origin <branch>Force push (overwrites remote history)Destructive
git push --force-with-leaseDiscard changes to a file (unstaged)
git restore <file>Unstage a file (keep changes)
git restore --staged <file>Undo last commit, keep changes staged
git reset --soft HEAD~1Undo last commit, keep changes unstaged
git reset HEAD~1Undo last commit and discard all changesDestructive
git reset --hard HEAD~1Create a new commit that undoes a previous commit
git revert <commit-hash>Remove untracked filesDestructive
git clean -fdStash current changes
git stashStash with a descriptive message
git stash push -m "message"List all stashes
git stash listApply and remove the latest stash
git stash popApply a stash without removing it
git stash apply stash@{0}Delete a specific stash
git stash drop stash@{0}Show details of a commit
git show <commit-hash>Show who changed each line of a file
git blame <file>Show history of HEAD changes (recovery tool)
git reflogSummarize commits by author
git shortlog -snList all tags
git tagCreate an annotated tag
git tag -a v1.0.0 -m "Release 1.0.0"Push tags to remote
git push origin --tagsDelete a local tag
git tag -d <tag-name>