Created
April 8, 2025 15:39
-
-
Save victorocna/9d9292def364df509e34b61a8fc8d6f0 to your computer and use it in GitHub Desktop.
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
git config --global alias.it '!f() { \ | |
# Try to get current branch, suppress stderr from rev-parse itself | |
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null); \ | |
# Check exit status AND content | |
if [ $? -ne 0 ] || [ -z "$current_branch" ] || [ "$current_branch" = "HEAD" ]; then \ | |
echo "Error: Failed to determine current branch." >&2; \ | |
echo "Please ensure you are in a valid Git repository with at least one commit." >&2; \ | |
return 1; \ | |
fi; \ | |
\ | |
if [ -z "$1" ]; then \ | |
echo "Error: Commit message is required." >&2; \ | |
return 1; \ | |
fi; \ | |
commit_message="$1"; \ | |
\ | |
echo ""; \ | |
echo "Will execute the following actions:"; \ | |
echo " 1. git add ."; \ | |
echo " 2. git commit -m \"$commit_message\""; \ | |
echo " 3. git push origin \"$current_branch\""; \ | |
echo ""; \ | |
read -p "Press ENTER to confirm, any other key + ENTER to cancel: " confirmation; \ | |
echo ""; \ | |
if [ -z "$confirmation" ]; then \ | |
echo "Proceeding..."; \ | |
git add . && \ | |
echo "Successfully added files." && \ | |
git commit -m "$commit_message" && \ | |
echo "Successfully committed." && \ | |
{ \ | |
if git rev-parse --abbrev-ref "$current_branch@{u}" > /dev/null 2>&1; then \ | |
git push origin "$current_branch"; \ | |
else \ | |
git push --set-upstream origin "$current_branch"; \ | |
fi \ | |
} && \ | |
echo "Successfully pushed branch '\''$current_branch'\'' to '\''origin'\''." || \ | |
{ echo "Error during git operations." >&2; return 1; }; \ | |
else \ | |
echo "Operation cancelled by user."; \ | |
return 1; \ | |
fi; \ | |
}; f "$@"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment