Git Command Reference
Find the right git command by describing what you want to do — not by memorizing command names.
Basics
Init, clone, commit, push, pull
Initialize a repo
Create a new Git repository in the current directory or a new folder.
git initClone a repo
Download a remote repository to your local machine.
git clone https://github.com/user/repo.gitCheck status
See which files are staged, unstaged, or untracked.
git statusStage files
Add files to the staging area before committing.
git add filename.txtMake a commit
Save staged changes to the repository with a message.
git commit -m "your message here"Push changes
Upload your local commits to a remote repository.
git push origin mainPull changes
Download and integrate changes from a remote repository.
git pullSet up .gitignore
Tell Git which files and folders to ignore.
touch .gitignoreConfigure Git
Set up your name, email, editor and other Git preferences.
git config --global user.name "Your Name"Branching
Create, merge, rebase, switch
Create a branch
Create a new branch to work on a feature or fix.
git switch -c feature/my-featureSwitch branches
Move between branches in your repository.
git switch branch-nameList branches
View all local and remote branches in your repository.
git branchRename a branch
Rename a local or remote branch.
git branch -m new-nameDelete a branch
Remove local and remote branches you no longer need.
git branch -d branch-nameMerge a branch
Integrate changes from one branch into another.
git switch mainRebase a branch
Reapply commits on top of another branch for a linear history.
git rebase mainResolve conflicts
Fix conflicting changes when merging or rebasing.
git statusUndoing
Reset, revert, discard changes
Undo last commit
Remove or undo the most recent commit, with or without keeping your changes.
git reset --soft HEAD~1Amend last commit
Fix the last commit message or add forgotten files.
git commit --amend -m "correct message here"Undo pushed commit
Remove or reverse a commit that has already been pushed to a remote repository.
git revert HEADRevert a commit
Create a new commit that undoes the changes from a previous commit.
git revert HEADDiscard changes
Remove unstaged or staged changes from your working directory.
git restore filename.txtUnstage a file
Remove a file from the staging area without losing changes.
git restore --staged filename.txtRemote
Fetch, push, remotes, tracking
Add a remote
Connect your local repository to a remote like GitHub or GitLab.
git remote add origin https://github.com/user/repo.gitChange remote URL
Update the URL of a remote repository — switch from HTTPS to SSH or change repo.
git remote set-url origin https://github.com/user/new-repo.gitStashing
Save, apply, list, drop stashes
Stash changes
Temporarily save uncommitted changes so you can switch context.
git stashApply a stash
Restore stashed changes back to your working directory.
git stash applyList stashes
See all saved stashes and their contents.
git stash listDelete a stash
Remove one or all stashes from the stash list.
git stash dropHistory
Log, diff, blame, search
View commit history
Browse and search through past commits.
git logSearch commits
Find commits by message, content, author or date.
git log --grep="fix login"View diffs
See exactly what changed in files, commits or branches.
git diffInspect a commit
View the full details and changes of a specific commit.
git showGit blame
Find out who last changed each line of a file and when.
git blame filename.txtAdvanced
Cherry-pick, bisect, worktrees
Cherry-pick a commit
Apply a specific commit from one branch to another.
git cherry-pick abc1234Squash commits
Combine multiple commits into a single commit.
git rebase -i HEAD~3Find bugs with bisect
Use binary search to find which commit introduced a bug.
git bisect startGit worktree
Work on multiple branches simultaneously without stashing.
git worktree add ../hotfix hotfix-branchGit submodules
Include and manage external repositories inside your repository.
git submodule add https://github.com/user/repo.git path/to/submoduleAbout This Reference
Most git references are organized by command name. This one is organized by what you are trying to do. Whether you want to undo a commit, rename a branch, squash commits before a pull request, or find which commit introduced a bug — search by intent and get the right command with a plain English explanation.
Each entry shows multiple options where relevant — for example, undoing a commit has three variants depending on whether you want to keep changes staged, keep them unstaged, or discard them entirely. Dangerous commands are clearly marked with warnings.