Create A Git Push Shortcut In Bash
Create a Git Push Shortcut in Bash/Zsh
📌 Step 1: Open Your Shell Configuration File
Depending on your shell, open the appropriate config file:
For Bash
nano ~/.bashrc
For Zsh
nano ~/.zshrc
📝 Step 2: Add the push Function
Paste the following at the bottom of the file:
# Git push shortcut: push "Your commit message"
function push() {
if [ -z "$1" ]; then
echo "❌ Commit message is required."
return 1
fi
git add .
git commit -m "$1"
branch=$(git rev-parse --abbrev-ref HEAD)
git push origin "$branch"
}
🔄 Step 3: Reload Your Shell
Apply changes without restarting the terminal:
For Bash
source ~/.bashrc
For Zsh
source ~/.zshrc
🚀 Step 4: Use the Command
push "Your commit message here"
This will:
- Stage all changes (
git add .) - Commit with your message
- Push to the current branch