Skip to content

Instantly share code, notes, and snippets.

@dgraham
Created September 8, 2023 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgraham/d947867d3089803af3b4712c82a63ec3 to your computer and use it in GitHub Desktop.
Save dgraham/d947867d3089803af3b4712c82a63ec3 to your computer and use it in GitHub Desktop.
git cowork
#!/bin/sh
if [ "$1" = "--stop" ]
then
git config --unset-all cowork.author
elif [ -n "$1" ]
then
author=$(git log --no-merges --author "$1" -1 --pretty="%an <%ae>")
if [ -n "$author" ]
then
git config --add cowork.author "$author"
echo "$author"
cat <<EOF > .git/hooks/commit-msg
#!/bin/sh
git config --get-all cowork.author | while read -r author
do
git interpret-trailers --in-place --trailer "Co-authored-by: \$author" "\$1"
done
EOF
chmod u+x .git/hooks/commit-msg
else
echo "Author not found"
exit 1
fi
else
git log --no-merges --author "$1" --pretty="%an <%ae>" | sort | uniq
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment