BASH

Git Workflow: Check Status & Stage Files

Streamline your Git workflow with a Bash script to quickly check repository status, view diffs, and interactively stage specific files for commit.

#!/bin/bash

# Navigate to your Git repository (optional, or run from root)
# cd /path/to/your/git/repo

echo "--- Current Git Status ---"
git status --short

# Check for uncommitted changes
if [[ -n "$(git status --porcelain)" ]]; then
    echo "
--- Uncommitted Changes Detected ---"
    
    read -p "Do you want to review and stage changes interactively? (y/N): " choice
    
    if [[ "$choice" =~ ^[Yy]$ ]]; then
        echo "Starting interactive staging (git add -p)..."
        git add -p
        echo "
Interactive staging complete. New status:"
        git status --short
    else
        echo "Skipping interactive staging. To stage all changes, use 'git add .'."
    fi
else
    echo "
No uncommitted changes found. Repository is clean."
fi

echo "
--- Current Branch ---"
git rev-parse --abbrev-ref HEAD
How it works: This script helps streamline common Git operations. It first provides a concise overview of the repository's status using `git status --short`. If uncommitted changes are detected, it offers an interactive prompt to stage changes using `git add -p`. This allows developers to review and select specific hunks or files to stage for the next commit. Finally, it displays the current branch name, which is often useful context for developers.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs