Created
June 9, 2024 09:38
-
-
Save mjtiempo/fcf1a3b41b5aa3c357a2b24dcc3f6ebd to your computer and use it in GitHub Desktop.
Lazy git add, commit, push
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
#!/bin/bash | |
# Check if the script is run inside a git repository | |
if ! git rev-parse --is-inside-work-tree &>/dev/null; then | |
echo "Not inside a git repository. Exiting." | |
exit 1 | |
fi | |
# Check if there are modified files | |
if [ -z "$(git ls-files -m)" ]; then | |
echo "Nothing to commit. Exiting now." | |
exit 1 | |
fi | |
# Get the current branch name | |
BRANCH=$(git branch --show-current) | |
echo "Current branch: $BRANCH" | |
# Prompt for commit message | |
read -p 'Enter commit message: ' commit_message | |
# Validate commit message | |
if [[ -z "${commit_message// /}" ]]; then | |
echo "Invalid or missing commit message. Exiting." | |
exit 1 | |
fi | |
# Combine branch name and commit message | |
GIT_COMMIT_MESSAGE="$BRANCH $commit_message" | |
# Add all changes to staging and commit | |
git add . | |
git commit -m "$GIT_COMMIT_MESSAGE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment