The Git Auto Pull Push Script

Automating Git Workflow with a Simple Auto Push Script

Working with Git is a huge advantage in modern development. It simplifies collaboration, keeps a clear history of changes, and makes it easy to experiment without fear.

But in day-to-day work, especially when you’re committing and pushing frequently, the process can become repetitive and frustrating.

To streamline this, I built a small shell script that automates the most common Git workflow into a single command.

#!/bin/zsh
CYAN='\033[0;36m'
NC='\033[0m' # No Color

# Get current Git branch
CURRENT_BRANCH=$(git branch --show-current)

# Commit message prompt
if [ "$#" -lt 1 ]; then
  echo "No commit message given. Enter one now:"
  read a
else
  a=$1
fi

# Determine branch to push to
if [ "$#" -eq 2 ]; then
  b=$2
else
  echo "Push to current branch (${CYAN}${CURRENT_BRANCH}${NC})? [Y/n]"
  read y
  case $y in
  [Nn]*) 
    echo "Enter Branch Name:"
    read b ;;
  *) 
    b=$CURRENT_BRANCH ;;
  esac
fi

# Confirm push
git status
echo "Do you want to push? [Y/n]"
read yn
case $yn in
[Yy]*)
  echo "----- Pushing to ${CYAN}${b}${NC} with commit ${CYAN}${a}${NC} -----"
  git add -A
  git commit -m "${a}"
  git pull origin $b
  git push origin $b
  ;;
[Nn]*) exit ;;
*) echo "Please answer yes or no" ;;
esac

What This Script Does

This script combines multiple Git steps into one simple flow:

  • Displays current repository status
  • Prompts for a commit message if not provided
  • Detects your current branch automatically
  • Allows optional branch override
  • Asks for confirmation before proceeding
  • Executes:
    • git add -A
    • git commit
    • git pull
    • git push

It reduces repetitive typing while still keeping you fully in control of what gets pushed.

Key Features

Smart Branch Detection

Automatically uses your current working branch instead of relying on a fixed default.

Interactive Control

Prompts before pushing so you can verify changes and avoid mistakes.

Flexible Usage

Supports both quick commands and fully interactive mode.

Clean Terminal Output

Includes colored output for better visibility during execution.

Installation

Create the Script File

vim /usr/bin/git.sh

Make It Executable

chmod +x /usr/bin/git.sh

Run the Script

sh /usr/bin/git.sh

Using an Alias (Recommended)

To make the workflow even faster, create a shortcut command.

Open Your Shell Config

vim ~/.bashrc   # or ~/.zshrc

Add Alias

alias gitpush="sh /usr/bin/git.sh"

Reload Configuration

source ~/.bashrc

Now you can simply run:

gitpush

Usage Examples

1. Quick Commit and Push

gitpush "Fixed header layout"

Pushes changes using your current branch.

2. Push to a Specific Branch

gitpush "Fixed header layout" "development"

Pushes changes to the specified branch.

3. Interactive Mode

gitpush
  • Prompts for commit message
  • Confirms branch
  • Confirms push

Why This Helps

This script removes the friction of running multiple Git commands repeatedly while still keeping the process transparent and safe.

It’s especially useful when:

You want a faster workflow without sacrificing control

You commit frequently throughout the day

You switch between branches often

Final Thoughts

Small automation like this can make a noticeable difference in daily productivity.

Instead of typing the same commands over and over, you can focus on writing code while your workflow stays fast, consistent, and reliable.