Setup & Config
7 snippetsInitial configuration
Set Username
git config --global user.name "Your Name"Set Email
git config --global user.email "you@example.com"Set Default Editor
git config --global core.editor "code --wait"Set Default Branch
git config --global init.defaultBranch mainView Config
git config --listInitialize Repo
git initClone Repo
git clone https://github.com/user/repo.git
git clone git@github.com:user/repo.gitBasic Commands
6 snippetsEveryday operations
Check Status
git statusStage Files
git add file.txt # Single file
git add . # All changes
git add -p # InteractiveCommit
git commit -m "message"
git commit -am "message" # Add + commit trackedView Log
git log
git log --oneline
git log --graph --oneline --allShow Diff
git diff # Unstaged changes
git diff --staged # Staged changes
git diff HEAD~1 # Last commitRemove File
git rm file.txt # Delete and stage
git rm --cached file.txt # Untrack but keepBranches
6 snippetsCreate and manage branches
List Branches
git branch # Local
git branch -r # Remote
git branch -a # AllCreate Branch
git branch feature-x
git checkout -b feature-x # Create and switchSwitch Branch
git checkout main
git switch main # Git 2.23+Rename Branch
git branch -m old-name new-name
git branch -m new-name # Current branchDelete Branch
git branch -d feature-x # Safe delete
git branch -D feature-x # Force deleteMerge Branch
git checkout main
git merge feature-xTired of looking up syntax?
DocuWriter.ai generates documentation and explains code using AI.
Remote Operations
6 snippetsWork with remote repositories
Add Remote
git remote add origin https://github.com/user/repo.gitView Remotes
git remote -vFetch
git fetch origin # Get remote changes
git fetch --all # All remotesPull
git pull # Fetch + merge
git pull --rebase # Fetch + rebasePush
git push origin main
git push -u origin main # Set upstream
git push --force # Force (careful!)Delete Remote Branch
git push origin --delete feature-xUndo & Reset
6 snippetsRevert and fix mistakes
Unstage File
git restore --staged file.txt
git reset HEAD file.txt # Older syntaxDiscard Changes
git restore file.txt
git checkout -- file.txt # Older syntaxAmend Last Commit
git commit --amend -m "new message"
git commit --amend --no-edit # Keep messageReset to Commit
git reset --soft HEAD~1 # Keep changes staged
git reset --mixed HEAD~1 # Keep changes unstaged
git reset --hard HEAD~1 # Discard changesRevert Commit
git revert abc123 # Create undo commitRecover Lost Commit
git reflog
git checkout abc123Stash
6 snippetsTemporarily save changes
Stash Changes
git stash
git stash -m "work in progress"List Stashes
git stash listApply Stash
git stash apply # Keep stash
git stash pop # Apply and removeApply Specific
git stash apply stash@{2}Drop Stash
git stash drop stash@{0}
git stash clear # Remove allStash Untracked
git stash -u # Include untrackedRebase
5 snippetsRewrite commit history
Rebase onto Main
git checkout feature
git rebase mainInteractive Rebase
git rebase -i HEAD~3 # Last 3 commits
# pick, squash, edit, drop, rewordContinue Rebase
git rebase --continueAbort Rebase
git rebase --abortSquash Commits
# In interactive rebase:
# pick abc123 First commit
# squash def456 Second commitTags
5 snippetsMark specific points in history
List Tags
git tagCreate Tag
git tag v1.0.0
git tag -a v1.0.0 -m "Release 1.0.0"Tag Specific Commit
git tag v1.0.0 abc123Push Tags
git push origin v1.0.0
git push origin --tags # All tagsDelete Tag
git tag -d v1.0.0
git push origin --delete v1.0.0