Skip to content

Instantly share code, notes, and snippets.

@Summonshr
Last active January 27, 2024 04:21
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 Summonshr/43e7dd046ec289b4e1bab92a4b79f1fb to your computer and use it in GitHub Desktop.
Save Summonshr/43e7dd046ec289b4e1bab92a4b79f1fb to your computer and use it in GitHub Desktop.
Modify pre commit message as per you require
#!/bin/bash
branch_name=$(git symbolic-ref --short HEAD) # Get the current branch name
short_branch_name=$(echo "$branch_name" | cut -c 1-8) # Extract the first 8 characters
# If the commit message file doesn't exist or is empty, use the default commit message
if [ ! -s "$1" ]; then
echo "$short_branch_name: " > "$1"
else
# Append the branch name to the beginning of the commit message
sed -i.bak -e "1s/^/$short_branch_name: /" "$1"
rm "$1.bak"
fi
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment