git flags & options
--oneline
Compact log output: one commit per line showing short hash and message.
git log --oneline
git log --oneline -10
--graph
Draw a text-based graph of the branch structure alongside the log.
git log --oneline --graph --all
--amend
Replace the most recent commit with a new one (same changes + any staged changes).
git commit --amend -m "updated message"
git commit --amend --no-edit
--no-edit
Keep the existing commit message when amending or during operations like cherry-pick.
git commit --amend --no-edit
git cherry-pick abc123 --no-edit
--force, -f
Force-push to remote, overwriting remote history. Dangerous. Prefer --force-with-lease.
git push --force origin feature-branch
git push --force-with-lease origin feature-branch
--cached, --staged
Operate on the staging area (index) instead of the working tree. Both names mean the same thing.
git diff --cached
git rm --cached file.txt
--stat
Show a summary of changed files and insertions/deletions instead of full diffs.
git diff --stat
git log --stat -5
--no-ff
Force a merge commit even when fast-forward is possible. Preserves branch history.
git merge --no-ff feature-branch
--hard
Reset working tree and index to match the target commit. Discards all uncommitted changes.
git reset --hard HEAD~1
git reset --hard origin/main
--soft
Reset HEAD to the target commit but keep all changes staged. Nothing is lost.
git reset --soft HEAD~1
--mixed
Default reset mode. Moves HEAD and unstages changes, but keeps working tree intact.
git reset HEAD~1
-b
Create and switch to a new branch in one step.
git checkout -b new-feature
git switch -c new-feature
-u, --set-upstream-to
Set the upstream (tracking) branch for the current branch.
git push -u origin feature-branch
git branch --set-upstream-to=origin/main
--patch, -p
Interactively select hunks of changes to stage, unstage, or discard.
git add -p
git checkout -p
git stash push -p
--dry-run, -n
Show what would happen without actually doing it.
git clean -n
git push --dry-run
git add --dry-run .