Dump of all commands from "So You Think You Know Git - FOSDEM 2024":
The full blog post: https://blog.gitbutler.com/git-tips-and-tricks/
# All ignored and untracked files are also stashed and then cleaned up with `git clean`.
git config --global alias.staash 'stash --all'# Download the script here: https://gist.github.com/schacon/e9e743dee2e92db9a464619b99e94eff
# To run an arbitrary shell script
git config --global alias.bb !better-git-branch.sh[includeIf "gitdir:~/projects/work/"]
path = ~/projects/work/.gitconfig
[includeIf "gitdir:~/projects/oss/"]
path = ~/projects/oss/.gitconfig# Blame a line range
git blame -L 15,26 path/to/file...equivalent for git log:
# Inspect line range over time
git log -L 15,26:path/to/file# Inspect a symbol called "Foo" (e.g. a class) over time
git log -L :Foo:path/to/file# Ignore whitespace
git blame -w# Ignore whitespace,
# and detect lines moved or copied in the same commit
git blame -w -C# Ignore whitespace,
# and detect lines moved or copied in the same commit,
# or the commit that created the file
git blame -w -C -C# Ignore whitespace,
# and detect lines moved or copied in the same commit,
# or the commit that created the file,
# or any commit at all
git blame -w -C -C -C# Find all the commits where `<some-text>` appears in the diff
git log -S <some-text> -pYou can reverse it as well, to get the oldest commit first:
git log -S <some-text> -p --source --all --reverse# Shows when the tips of branches and other references were updated in the local repository
git reflog# When you want to look at diffs inside a line
git diff --word-diff# (RE)use (RE)corded (RE)solution
# Remember how you solved conflicts, to reapply them later automatically
git config --global rerere.enabled truegit branch --columnor enable it globally:
git config --global column.ui auto# Sort branches by most recent commit first
git config --global branch.sort -committerdate# Safer force push
git push --force-with-lease# Signing commits with SSH
git config gpg.format ssh
git config user.signingkey ~/.ssh/key.pub# Not supported by GitHub or GitLab
git push --signed# Building commit graph, prefetching, removing loose objects and incremental repack automatically
git maintenance start# Faster `git log --graph --oneline`
git commit-graph write# Write commit graph on fetch
git config --global fetch.writeCommitGraph true# Filesystem monitor for faster `git status`
git config core.untrackedcache true
git config core.fsmonitor true# Do not clone blobs, and only do it on-demand
git clone --filter=blob:none# Good for CI
git clone --filter=tree:0# Only checkout `build` and `base` folders
git sparse-checkout set build base# Fetch all PRs automatically on `git fetch`
git config remote.origin.fetch '+refs/pull/*:refs/remotes/origin/pull/*'