Skip to content

Instantly share code, notes, and snippets.

@bonelifer
Forked from theHilikus/commit-alias.sh
Last active April 17, 2024 20:48
Show Gist options
  • Save bonelifer/8317c24b5a242727d438101712baf36a to your computer and use it in GitHub Desktop.
Save bonelifer/8317c24b5a242727d438101712baf36a to your computer and use it in GitHub Desktop.
alias to create empty commits
#!/bin/bash
# Function: commit
# Description: Commits changes to the current branch with an empty commit message containing the branch name.
commit() {
# Check if the current directory is within a Git repository
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
echo "Error: Not in a Git repository. Please navigate to a Git repository directory."
return 1
fi
# Get the name of the current branch
branchName=$(git rev-parse --abbrev-ref HEAD)
# Commit changes with an empty commit message containing the branch name
git commit --allow-empty -m "Branch name: $branchName"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment