Git Commands Cheatsheet
Master version control with essential Git command structures — from configuration to advanced stashing, merging, and interactive rebasing.
Initial Setup & Config
git config --global user.name "Name"
Configure global username for commit attributes.
git config --global user.name "John Doe"
git config --global user.email "email"
Configure global email address for credentials.
git config --global user.email "john@doe.com"
git init
Initialize a new local Git repository in the current directory.
git init my-app
Staging & Committing
git status
List modified, untracked, and staged files.
git status --short
git add [file]
Stage file changes for the next commit. Use `.` for all files.
git add .
git commit -m "msg"
Record staged snapshot to repository history.
git commit -m "feat: add user login"
git commit --amend
Modify the most recent commit message or staged files.
git commit --amend -m "refactor: adjust login logic"
git reset HEAD [file]
Unstage file changes while keeping local modifications.
git reset HEAD index.php
Branches & Collaboration
git branch [name]
Create a new local branch at current commit.
git branch feature/auth
git checkout -b [name]
Create and immediately switch to the new branch.
git checkout -b feature/pay
git push [remote] [branch]
Upload local commits to the remote branch.
git push origin main
git merge [branch]
Merge branch changes into current active branch.
git merge feature/auth
git pull [remote] [branch]
Fetch updates from remote repository and merge them.
git pull origin staging
Advanced & Utility
git cherry-pick [commit]
Apply commits from other branches into the current branch.
git cherry-pick a1b2c3d
git stash push
Temporarily store all local dirty changes in stack.
git stash push -m "work-in-progress"
git stash pop
Restore the most recently stashed changes to working directory.
git stash pop
git log --oneline
Display commit history in a single-line compact format.
git log --oneline -n 5
No matching syntax found
Verify your query spelling or try searching another keyword.