git-scripting

Automate git commands in scripts and Makefiles with safe state checks.

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/christophevg/c3 --skill git-scripting
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-scripting
Source: https://github.com/christophevg/c3/tree/main/skills/git-scripting
Command: npx skills add https://github.com/christophevg/c3 --skill git-scripting

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents broken or unsafe automation when running git commands by ensuring scripts check the right state (current branch, upstream availability, dirty/unstaged changes) instead of producing false positives or pushing unintentionally.

Core Features & Use Cases

  • Safe push gating: Uses commit-ahead checks against the current branch’s upstream to decide whether a push should happen.
  • Repository-state detection: Detects uncommitted changes, untracked files, detached HEAD, and whether a directory is a git repository (including worktrees).
  • Makefile correctness: Applies Makefile-specific practices like escaping dollar signs and using proper phony targets to avoid subtle shell/variable bugs.
  • Use Case: You want a Makefile target that scans multiple repo folders, pushes only those with commits ahead of upstream, and prints helpful branch/ahead information without spamming errors.

Quick Start

Ask for git-scripting guidance to write a Makefile target that pushes only the current branch when it is ahead of its upstream and skips repos that are missing upstream or have no git checkout.

Frequently Asked Questions about git-scripting

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I check if a git branch has commits ahead of its upstream in a shell script?

To check if a git branch is ahead in a script, compute the commit count using the range @{upstream}..HEAD. This ensures your automation only triggers actions like a safe push when local commits actually exist to publish.

What is the best way to prevent unintended git pushes in a Makefile?

Preventing unintended git pushes in a Makefile requires safe push gating that validates repository state. By checking uncommitted changes and upstream availability first, scripts avoid pushing unintentionally or failing on detached HEAD states.

How do I detect uncommitted changes or untracked files across multiple git repositories?

Detecting uncommitted changes across multiple repositories involves iterating through folders with git commands using quiet flags. This repository-state detection identifies dirty directories and untracked files without spamming CI/CD logs with unnecessary errors.

How do I handle missing upstream tracking when automating git commands?

Handling missing upstream tracking requires explicit validation in your scripts before executing push commands. Automation must check for upstream availability to prevent false positives and ensure correct commit-ahead computations against the current branch.

Why does my Makefile git command fail with a detached HEAD state?

Makefile git commands fail during detached HEAD states because scripts lack proper repository-state detection. Escaping dollar signs correctly and using quiet flags ensures the script safely identifies the context before running push operations.