Gh Commit And Push
Overview
Automate a safe, repeatable git workflow that syncs with origin, stages changes, summarizes diffs, generates a detailed commit message, commits, and pushes.
Workflow
- Choose the target branch.
- If a branch name is provided, switch to it (create locally from origin if needed) and use it for commit and push.
- Otherwise, use the current branch.
- Pull from origin with fast-forward only.
- Fetch from origin.
- Pull
origin/<branch>with--ff-onlyto avoid accidental merges.
- Stage and inspect changes.
- Stage new and modified files with
git add -A. - Inspect
git status --shortandgit diff --cached --stat.
- Generate a detailed commit message and commit.
- Title: concise summary (include file count or key files).
- Body: bullet list of changed files plus diff stats.
- Commit with the generated message.
- Push to origin.
- Push the target branch to origin.
Quick Command
Use the script for a one-shot workflow:
scripts/gh_commit_and_push.sh [branch]
- If
[branch]is provided, the script will checkout or create it, pull from origin, commit there, and push toorigin/<branch>. - If omitted, it uses the current branch.
Notes
- If there are no staged changes after
git add -A, exit without committing. - Always show
git status --shortandgit diff --cached --statbefore committing to ensure the commit message matches the actual changes.
Resources
scripts/
gh_commit_and_push.sh: Pulls from origin, stages changes, inspects diffs, builds a detailed commit message, commits, and pushes.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.