**Git command cheat sheet**
---
## Configuration & Setup
* `git --version` → Show installed Git version.
* `git config --global [Link] "Name"` → Set your global username.
* `git config --global [Link] "email@[Link]"` → Set your global email.
* `git config --list` → View all Git configurations.
---
## Repository Management
* `git init` → Create a new Git repository in current folder.
* `git clone <repo-url>` → Copy a remote repository locally.
---
## Basic Snapshotting
* `git status` → Show changes (staged, unstaged, untracked).
* `git add <file>` → Stage a file for commit.
* `git add .` → Stage all modified/untracked files.
* `git reset <file>` → Unstage a file (keep changes).
* `git diff` → Show unstaged changes.
* `git diff --staged` → Show staged changes.
* `git commit -m "message"` → Commit staged changes with a message.
* `git commit -am "message"` → Stage and commit all tracked changes.
* `git rm <file>` → Remove file from repo and working directory.
* `git mv <old> <new>` → Rename or move a file.
---
## Branching & Merging
* `git branch` → List all branches.
* `git branch <name>` → Create a new branch.
* `git checkout <branch>` → Switch to another branch.
* `git switch <branch>` → Alternative to checkout for switching.
* `git checkout -b <branch>` → Create and switch to new branch.
* `git merge <branch>` → Merge branch into current branch.
* `git branch -d <branch>` → Delete a branch (safe).
---
## Remote Repositories
* `git fetch` → Download changes without merging.
* `git pull` → Fetch and merge changes from remote.
* `git pull origin <branch>` →
* `git push` → Upload local commits to remote.
* `git push -u origin <branch>` → Push branch and set upstream.
* `git push origin --delete <branch>` → Delete a branch on remote.
---
## Undoing Changes
* `git checkout -- <file>` → Discard local changes in file.
* `git restore <file>` → Restore file (modern alternative).
* `git reset --soft HEAD~1` → Undo last commit (keep changes staged).
* `git reset --mixed HEAD~1` → Undo last commit (keep changes unstaged).
* `git reset --hard HEAD~1` → Undo last commit (discard changes).
* `git revert <commit>` → Create a new commit that undoes given commit.
---
## Stashing (Temporary Save)
* `git stash` → Save changes without committing.
* `git stash pop` → Reapply last stashed changes.
* `git stash list` → Show stashed changes.
* `git stash drop` → Delete a stash.
---
## Viewing History
* `git log` → Show commit history.
* `git log --oneline` → Show compact commit history.
* `git log --graph --oneline --decorate` → Visual branch history.
* `git show <commit>` → Show details of a commit.
---
## Tags & Releases
* `git tag` → List all tags.
* `git tag <name>` → Create a lightweight tag.
* `git tag -a <name> -m "msg"` → Create an annotated tag.
* `git push origin <tag>` → Push a tag to remote.
* `git push origin --tags` → Push all tags.
---
## Advanced
* `git rebase <branch>` → Reapply commits on top of another branch.
* `git cherry-pick <commit>` → Apply a specific commit from another branch.