Home Services Blog About Contact

Git Commit & Push Script

Automate your git commits with proper identity configuration. These scripts set your name and email, stage changes, and push to the remote repository.

commit.ps1 (PowerShell - Windows)
Param(
    [Parameter(Mandatory = $true)]
    [string]$Message,

    [string]$Name  = "Tharun Wegworks",
    [string]$Email = "[email protected]"
)

# Ensure you are inside a Git repo
if (-not (Test-Path ".git")) {
    Write-Host "❌ Not a Git repository. CD into your repo folder first."
    exit 1
}

# Set identity for this repo
git config user.name  $Name
git config user.email $Email

Write-Host "✅ Using identity: $Name <$Email>"

# Stage all changes
git add -A
Write-Host "📦 Staged all changes"

# Commit with the provided message
git commit -m $Message
Write-Host "✔️ Committed: $Message"

# Push to remote
git push
Write-Host "🚀 Pushed to remote successfully!"
commit.sh (Bash - macOS/Linux)
#!/bin/bash

# Git Commit & Push Script for WegWorks
# Usage: ./commit.sh "Your commit message"

NAME="Tharun Wegworks"
EMAIL="[email protected]"

# Check if commit message is provided
if [ -z "$1" ]; then
    echo "❌ Error: Please provide a commit message"
    echo "Usage: ./commit.sh \"Your commit message\""
    exit 1
fi

# Check if inside a git repository
if [ ! -d ".git" ]; then
    echo "❌ Not a Git repository. CD into your repo folder first."
    exit 1
fi

# Set identity for this repo
git config user.name "$NAME"
git config user.email "$EMAIL"

echo "✅ Using identity: $NAME <$EMAIL>"

# Stage all changes
git add -A
echo "📦 Staged all changes"

# Commit with the provided message
git commit -m "$1"
echo "✔️ Committed: $1"

# Push to remote
git push
echo "🚀 Pushed to remote successfully!"

Pro Tip

These scripts set the git identity locally for the repository. This won't affect your global git configuration on other projects.

How to Use

1

Save the Script

Save as commit.ps1 (Windows) or commit.sh (macOS/Linux) in your project root or a scripts folder.

2

Make it Executable (Bash only)

Run chmod +x commit.sh to make the script executable on macOS/Linux.

3

Run the Script

PowerShell: .\commit.ps1 -Message "Your commit message"
Bash: ./commit.sh "Your commit message"

PowerShell Execution Policy

If you get an execution policy error on Windows, run: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Quick Git Commands Reference

Common Git Commands
# Check current status
git status

# View commit history
git log --oneline -10

# Create a new branch
git checkout -b feature/your-feature-name

# Switch branches
git checkout main

# Pull latest changes
git pull origin main

# Discard local changes to a file
git checkout -- filename.txt

# Stash changes temporarily
git stash
git stash pop

# View diff of changes
git diff