BASH
Automate Git Operations and Check Status
A bash script to automate common Git operations like pulling latest changes, pushing committed code, and checking the repository status, simplifying development and deployment workflows.
#!/bin/bash
# Automate common Git operations: pull, push, status.
# Usage: ./git_workflow.sh [pull|push|status]
ACTION="$1"
if [ -z "$ACTION" ]; then
echo "Usage: $0 <pull|push|status>"
exit 1
fi
case "$ACTION" in
pull)
echo "Executing: git pull..."
git pull
;;
push)
echo "Executing: git push..."
git push
;;
status)
echo "Executing: git status..."
git status
;;
*)
echo "Invalid action: $ACTION"
echo "Usage: $0 <pull|push|status>"
exit 1
;;
esac
# Check the exit status of the last command
if [ $? -eq 0 ]; then
echo "Git operation '$ACTION' completed successfully."
else
echo "Git operation '$ACTION' failed."
exit 1
fi
How it works: This script streamlines repetitive Git tasks by accepting `pull`, `push`, or `status` as an argument and executing the corresponding `git` command. It checks the exit status of the Git command to report success or failure. This automation is particularly beneficial in Continuous Integration/Continuous Deployment (CI/CD) pipelines or for developers needing to quickly synchronize local repositories or assess the working directory's state without manual command input.