GIT Cheatsheet
š§ Setup
Command | Purpose |
---|---|
git config --global user.name "Your Name" |
Set your Git username |
git config --global user.email "you@example.com" |
Set your Git email |
git init |
Initialize a new Git repository |
git clone <repo-url> |
Clone an existing repository |
š Working with Files
Command | Purpose |
---|---|
git status |
Show current changes and branch info |
git add <file> |
Stage a file for commit |
git add . |
Stage all changes |
git reset <file> |
Unstage a file |
git checkout -- <file> |
Discard changes in a file |
Ā
š¦ Commit & History
Command | Purpose |
---|---|
git commit -m "message" |
Commit staged changes |
git log |
View commit history |
git log --oneline |
Compact commit log |
git diff |
See changes not yet staged |
git diff --staged |
See changes staged for commit |
Ā
š Branching
Command | Purpose |
---|---|
git branch |
List branches |
git branch <name> |
Create new branch |
git checkout <name> |
Switch to a branch |
git checkout -b <name> |
Create and switch to new branch |
git merge <branch> |
Merge branch into current |
git branch -d <name> |
Delete a branch |
Ā
š Push & Pull
Command | Purpose |
---|---|
git remote -v |
Show remote repositories |
git push origin <branch> |
Push changes to remote |
git pull |
Fetch and merge changes from remote |
git fetch |
Fetch changes without merging |
Ā
š Undo & Rescue
Command | Purpose |
---|---|
git stash |
Temporarily save uncommitted changes |
git stash pop |
Restore stashed changes |
git reset --hard |
Reset working directory and staging area |
git merge --abort |
Abort a merge in progress |
Ā
š§ Tip:
Use git help <command>
or man git-<command>
for detailed docs.