Submodules
$git submodule add <url> path/Add submodule
$git submodule update --init --recursiveInit submodules
$git clone --recurse-submodules <url>
$git submodule foreach git pull origin mainUpdate all
$git submodule deinit path/ && git rm path/Remove
Worktrees
$git worktree add ../hotfix hotfix/v1.2.1Multiple branches at once
$git worktree list
$git worktree remove ../hotfix
Sparse Checkout (monorepos)
$git clone --filter=blob:none --sparse <url>
$git sparse-checkout set src/myservice
Interactive Rebase Actions
pick a1b2c3 Use commit as-is
reword a1b2c3 Change commit message
edit a1b2c3 Pause to amend commit
squash a1b2c3 Squash into previous
fixup a1b2c3 Squash, discard message
drop a1b2c3 Remove commit entirely
exec make test Run command after commit
Useful One-Liners
$git shortlog -sn --no-mergesCommit counts by author
$git diff HEAD~5 HEAD --statChanges in last 5 commits
$git log --all --full-history -- "**/deleted-file.php"Find deleted file
$git ls-files | xargs wc -lCount lines in repo
$git for-each-ref --sort=-committerdate refs/heads/Branches by date
$git diff --word-diffInline word changes
$git archive --format=zip HEAD > snapshot.zipExport repo
$git gc --aggressive --prune=nowCleanup + compress
$git count-objects -vHRepo size info