Last updated
Common Command Combinations
- Sync fork with upstream:
git fetch upstream && git rebase upstream/main - Clean up merged branches:
git branch --merged | grep -v main | xargs git branch -d - Find when a line was introduced:
git log -S "search string" --oneline - Show commits not yet in main:
git log main..HEAD --oneline - Undo last push (before others pull):
git reset --soft HEAD~1 && git push --force-with-lease
Examples
Example 1: Custom Git Log Commands
The log command has the most complex formatting options. The generator assembles them visually:
# Pretty one-line log with graph
git log --oneline --graph --decorate --all
# Detailed log with author, date, and color
git log --pretty=format:'%Cred%h%Creset - %C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
# Log for a specific author in a date range
git log --author="Alice" --after="2025-01-01" --before="2025-03-31" --oneline
# Log showing only files changed per commit
git log --name-only --oneline
# Log with patch (full diff) for a specific file
git log -p -- src/auth/login.js
Example 2: Reset Variants — Choosing the Right One
The generator explains the difference between reset modes and generates the correct variant:
# Undo last commit — keep changes STAGED
git reset --soft HEAD~1
# Undo last commit — keep changes in working directory (UNSTAGED)
git reset --mixed HEAD~1
# Undo last commit — DISCARD all changes (destructive)
git reset --hard HEAD~1
# Reset to a specific commit hash
git reset --soft abc1234
# Unstage a specific file only
git reset HEAD src/components/Button.jsx
The generator flags --hard with a warning: "This permanently discards uncommitted changes. Consider --soft or --mixed first."
Example 3: Interactive Rebase Commands
# Rebase last 4 commits interactively
git rebase -i HEAD~4
# Rebase onto a specific branch
git rebase -i main
# Rebase and automatically squash fixup commits
git rebase -i --autosquash main
# Continue after resolving conflicts
git rebase --continue
# Abort and return to original state
git rebase --abort