Last active
April 5, 2022 22:04
-
-
Save scottrigby/0c043c0bfbbdb5949e2d824fc3adeaa4 to your computer and use it in GitHub Desktop.
Add to ~/.bash_profile (or ~/.zshrc) to auto-sign git commits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Always signs commits for DCO (popularized by The Linux Foundation, required by | |
# most CNCF projects including Helm). | |
# See `git help commit`: | |
# > -s, --signoff | |
# > Add Signed-off-by line by the committer at the end of the commit log | |
# message. The meaning of a signoff depends on the project, but it typically | |
# certifies that committer has the rights to submit this work under the same | |
# license and agrees to a Developer Certificate of Origin (see | |
# http://developercertificate.org/ for more information). | |
git() { | |
if [ $# -gt 0 ] && [ "$1" == "commit" ] ; then | |
shift | |
command git commit --signoff "$@" | |
else | |
command git "$@" | |
fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For zsh: https://unix.stackexchange.com/a/607909 | |
git() { | |
setopt local_options extended_glob unset | |
local -i i=$argv[(i)^-*] | |
case $argv[i] in | |
commit) argv[i+1,i]=(--signoff);; | |
esac | |
command git "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note we could alternatively do this through a git hook (
cat .git/hooks/prepare-commit-msg.sample
to see how). That could be made global, but requires re-initing each existing repo as part of that process (see https://stackoverflow.com/a/8842663/4096495).This gist is a quick and easy solution that just requires a new shell session (
bash --login
, etc).