Skip to content

Instantly share code, notes, and snippets.

@rpavlik
Last active February 6, 2024 20:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpavlik/c5f297be79bab1077ecd26339dcb674f to your computer and use it in GitHub Desktop.
Save rpavlik/c5f297be79bab1077ecd26339dcb674f to your computer and use it in GitHub Desktop.
git-prep
#!/bin/sh
# SPDX-FileCopyrightText: 2020-2024, Rylie Pavlik
# SPDX-License-Identifier: CC0-1.0
# Nothing sh-specific here, these work fine in pwsh as well
### Aliases
# Lots of people use these, and I guess I type them a lot...
git config --global alias.ci commit
git config --global alias.co checkout
# Less common but I feel like this might be a helpful workflow improvement.
git config --global alias.ff "merge --ff-only"
# don't pull, git rup - updates all the remotes
git config --global alias.rup "remote update --prune"
# don't force-push, git pf for safety and to avoid losing work
git config --global alias.pf "push --force-with-lease --force-if-includes"
# sometimes --force-if-includes is annoying, so we have the old alias of pf here as pff
# ("really force")
git config --global alias.pff "push --force-with-lease"
# Sometimes required when e.g. you used `glab mr checkout 42`
git config --global alias.pfff "push --force"
# Fixup a commit, by hash (middle click paste from gitk is handy)
# Can specify partial commit message with ":/someregex" if you prefer, see
# https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt-emlttextgtemegemfixnastybugem
git config --global alias.fu "commit --fixup"
# Speedy shortcuts for rebase, these are my primary tools...
git config --global alias.rbi "rebase -i --autosquash"
git config --global alias.rbc "rebase --continue"
git config --global alias.rbs "rebase --skip"
git config --global alias.rba "rebase --abort"
# ASCII art logs - see http://blog.kfish.org/2010/04/git-lola.html
git config --global alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit"
git config --global alias.lola "log --graph --decorate --pretty=oneline --abbrev-commit --all"
### Config for pretty logs
git config --global color.branch auto
git config --global color.diff auto
git config --global color.interactive auto
git config --global color.status auto
### Other config
# only allow fast-forward pulls: make any merges/rebases manual and explicit
git config --global pull.ff only
# see the diff in the commit message editor
git config --global --bool commit.verbose true
# fix the default branch name
git config --global init.defaultBranch main
# Default to updating intermediate branches for better stacked branch experience:
# https://andrewlock.net/working-with-stacked-branches-in-git-is-easier-with-update-refs/
git config --global --bool rebase.updateRefs true
# Default to sorting `git branch` in reverse order of commit date:
# so branch with most recent commit date comes first, etc.
# Yes, the - before committerdate is important: otherwise it shows
# the oldest first.
git config --global branch.sort -committerdate
# Store repeated merge/rebase conflict resolutions
git config --global --bool rerere.enabled true
### Config that's new that I'm trying out
# submodule related
git config --global --bool status.submoduleSummary true
git config --global diff.submodule log
git config --global --bool submodule.recurse true
### User Identity
# Edit these before pasting!
git config --global user.name "Rylie Pavlik"
git config --global user.email "rylie.pavlik@collabora.com"
# git config --global user.email "rylie@ryliepavlik.com"
# Consider installing this interactive rebase tool:
# https://gitrebasetool.mitmaro.ca/
# Windows only
# needs scoop install notepad3 first, and also recommend going in and setting "esc key closes window"
git config --global core.editor notepad3
# make sure you ran scoop install kdiff3
git config --global merge.tool kdiff3
git config --global mergetool.kdiff3.cmd 'kdiff3 $BASE $LOCAL $REMOTE -o $MERGED'
git config --global credential.helper manager-core

To check if all commits are buildable, something like this:

git rebase -i --exec 'ninja -C build test $ref'

Similarly to apply clang format like in an OpenXR repo:

git rebase -i --exec './runClangFormat.sh' origin/main

Use the standard name for "revisions to ignore". Sadly, you cannot do this globally, because it is weird if you don't have that file in a given repo. Do this per-repo instead.

git config blame.ignoreRevsFile .git-blame-ignore-revs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment