Skip to content

Instantly share code, notes, and snippets.

@ignat-one
Created April 22, 2024 06:54
Show Gist options
  • Save ignat-one/6910f35601c96ac2bdac58cfa890bce7 to your computer and use it in GitHub Desktop.
Save ignat-one/6910f35601c96ac2bdac58cfa890bce7 to your computer and use it in GitHub Desktop.
git add . && git commit -m "<current branch name> <commit message>"
function gcommit() {
# Retrieve the current branch name
local branch_name=$(git rev-parse --abbrev-ref HEAD)
# Check if we successfully retrieved a branch name
if [ -z "$branch_name" ]; then
echo "Failed to detect Git branch name."
return 1
fi
# Add all changes and commit them
git add .
if git commit -m "$branch_name $1"; then
echo "Successfully committed on branch $branch_name."
else
echo "Commit failed."
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment