Quick reference for common Git operations in this project.
# Update master to latest
git checkout master
git fetch origin
git reset --hard origin/master
# Create feature branch
git checkout -b feature/my-feature# Stage changes
git add <file> # Stage specific file
git add . # Stage all changes
# Commit with conventional commit message
git commit -m "feat: add new feature"
git commit -m "fix: resolve bug"
git commit -m "docs: update README"
# Amend last commit (if needed)
git commit --amend# Fetch latest changes
git fetch origin
# Rebase on master
git rebase origin/master
# If conflicts occur:
# 1. Fix conflicts in files
# 2. git add <resolved-files>
# 3. git rebase --continue
# Or abort: git rebase --abort# First push
git push origin feature/my-feature
# After rebase (force push)
git push --force-with-lease origin feature/my-featuremake sync # Fetch and show status
make rebase-master # Rebase on origin/master
make rebase-main # Rebase on origin/main
make rebase-develop # Rebase on origin/develop
make check-branch # Check if rebase needed
make test # Run tests
make pre-commit # Run all pre-commit hooks# From current branch
git checkout -b feature/new-feature
# From specific branch
git checkout -b feature/new-feature master
# From specific commit
git checkout -b feature/new-feature abc1234# Switch to existing branch
git checkout feature/my-feature
# Switch to master and update
git checkout master
git fetch origin
git reset --hard origin/master# Delete local branch
git branch -d feature/old-feature
# Force delete local branch
git branch -D feature/old-feature
# Delete remote branch
git push origin --delete feature/old-feature# View commit history
git log
git log --oneline
git log --oneline --graph
git log --oneline --graph --all
# View changes
git diff # Unstaged changes
git diff --staged # Staged changes
git diff master # Compare with master
# View file history
git log -- <file>
git log -p -- <file> # With diffs
# View who changed what
git blame <file># Unstage specific file
git reset HEAD <file>
# Unstage all files
git reset HEAD# Discard changes in specific file
git checkout -- <file>
# Discard all changes
git checkout -- .
# Clean untracked files (careful!)
git clean -fd# Undo last commit (keep changes)
git reset --soft HEAD~1
# Undo last commit (discard changes)
git reset --hard HEAD~1
# Undo multiple commits
git reset --hard HEAD~3
# Undo to specific commit
git reset --hard abc1234# Create new commit that undoes a commit
git revert abc1234
# Revert multiple commits
git revert abc1234..def5678# Rebase on master
git fetch origin
git rebase origin/master
# Rebase on specific branch
git rebase origin/develop
# Continue after resolving conflicts
git rebase --continue
# Skip current commit
git rebase --skip
# Abort rebase
git rebase --abort# Rebase last 5 commits
git rebase -i HEAD~5
# Rebase from specific commit
git rebase -i abc1234
# Commands in interactive rebase:
# pick = use commit
# reword = use commit, but edit message
# edit = use commit, but stop for amending
# squash = use commit, but meld into previous
# fixup = like squash, but discard message
# drop = remove commit# Squash last 3 commits
git rebase -i HEAD~3
# In editor, change 'pick' to 'squash' for commits to combine
# Save and edit the combined commit message# Stash current changes
git stash
git stash save "work in progress"
# List stashes
git stash list
# Apply stash
git stash apply # Keep stash
git stash pop # Apply and remove stash
# Apply specific stash
git stash apply stash@{2}
# Delete stash
git stash drop stash@{0}
# Clear all stashes
git stash clear# Basic status
git status
# Short status
git status -s
git status -sb # With branch info
# Show what would be committed
git diff --cached
# Show all changes
git diff HEAD# List remotes
git remote -v
# Show remote details
git remote show origin# Fetch all remotes
git fetch --all
# Fetch specific remote
git fetch origin
# Fetch and prune deleted branches
git fetch --prune# Push to remote
git push origin feature/my-feature
# Force push (safer)
git push --force-with-lease origin feature/my-feature
# Push and set upstream
git push -u origin feature/my-feature
# Push all branches
git push --all origin
# Push tags
git push --tags<type>(<scope>): <description>
[optional body]
[optional footer]
feat: New featurefix: Bug fixdocs: Documentationstyle: Code style (formatting)refactor: Code refactoringtest: Testschore: Maintenanceperf: Performanceci: CI/CDbuild: Build system
git commit -m "feat: add voice cloning"
git commit -m "fix: resolve audio bug"
git commit -m "docs: update README"
git commit -m "test: add unit tests"
git commit -m "chore: update dependencies"# View reflog
git reflog
# Recover lost commit
git reset --hard HEAD@{1}
git cherry-pick abc1234# Move commits to new branch
git branch feature/correct-branch
git reset --hard origin/master
git checkout feature/correct-branch# Find commit before force push
git reflog
# Reset to that commit
git reset --hard HEAD@{1}
# Force push again (if needed)
git push --force-with-lease origin feature/my-feature# List merged branches
git branch --merged
# Delete merged branches
git branch --merged | grep -v "\*" | grep -v "master" | xargs -n 1 git branch -d
# Prune remote tracking branches
git fetch --prune# Install all hooks
pre-commit install
pre-commit install --hook-type commit-msg
pre-commit install --hook-type pre-push# Run all hooks on all files
pre-commit run --all-files
# Run specific hook
pre-commit run black --all-files
pre-commit run ruff --all-files
# Update hooks
pre-commit autoupdateAdd these to your ~/.gitconfig:
[alias]
# Short status
st = status -sb
# Pretty log
lg = log --oneline --graph --decorate
lga = log --oneline --graph --decorate --all
# Amend last commit
amend = commit --amend --no-edit
# Undo last commit (keep changes)
undo = reset --soft HEAD~1
# Update master
um = !git checkout master && git fetch origin && git reset --hard origin/master
# Rebase on master
rom = !git fetch origin && git rebase origin/master
# Force push with lease
fpush = push --force-with-lease
# Show branches
br = branch -vv
# Show remotes
rem = remote -vUsage:
git st # git status -sb
git lg # git log --oneline --graph
git um # Update master
git rom # Rebase on master
git fpush origin branch # Force push with lease# WARNING: This will discard ALL local changes
git fetch origin
git reset --hard origin/master
git clean -fd# Find the commit
git reflog
# Recreate branch
git checkout -b recovered-branch abc1234# Create branch from current position
git checkout -b temp-branch
# Or go back to master
git checkout master- Always use
--force-with-leaseinstead of--force - Fetch before rebasing to ensure you have latest changes
- Commit often with small, focused commits
- Use conventional commits for clear history
- Rebase before pushing to keep history clean
- Check status before committing:
git status - Review changes before committing:
git diff - Use stash to save work in progress
- Use reflog to recover lost commits
- Test before pushing to avoid breaking CI