AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Git Post Merge Cleanup

skill-mishrashardendu22-agent-skills-git-post-merge-cleanup · by MishraShardendu22

>-

— No reviews yet
0 installs
30 views
0.0% view→install

Install

$ agentstack add skill-mishrashardendu22-agent-skills-git-post-merge-cleanup

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • ✓ Prompt-injection patterns
  • ✓ Secret / credential exfiltration
  • ✓ Dangerous shell & filesystem operations
  • ✓ Untrusted network calls
  • ✓ Known-malicious package signatures

What it can access

  • ✓ Network access No
  • ✓ Filesystem access No
  • ✓ Shell / process execution No
  • ✓ Environment & secrets No
  • ✓ Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-mishrashardendu22-agent-skills-git-post-merge-cleanup)

Reliability & compatibility

✓ Security review passed
0 installs to date
— no reviews yet
● 25d ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Git Post Merge Cleanup? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Git Post-Merge Repository & Branch Cleanup Skill

This skill defines the official protocol and step-by-step procedures for cleaning up local development branches, pulling the latest main from GitHub after a Pull Request is merged, and executing deep Git repository garbage collection and maintenance.


1. Strict Permission & Trigger Boundary

> [!IMPORTANT] > EXPLICIT HUMAN INSTRUCTION ONLY: > AI agents MUST NEVER run local branch deletions, branch resets, or aggressive garbage collection automatically. > This workflow is triggered ONLY when the human user explicitly instructs the agent to perform cleanup (e.g. "clean up local branches", "sync main and do git gc", "I merged the PR, please clean up"). > > The typical workflow is: > 1. AI agent finishes work on a feature branch, passes make pre-commit, commits locally, pushes branch, and opens a PR targeting main. > 2. The human user reviews and merges the Pull Request on GitHub. > 3. The human user prompts the AI agent to perform local cleanup. > 4. The AI agent executes the safe post-merge cleanup runbook below.


2. Core Cleanup Principles

  1. Safety-First Working Tree Verification: Never switch branches or run destructive cleanups if there are uncommitted changes or uncommitted work in progress.
  2. Main as the Source of Truth: Always switch to main and pull from origin/main first so that the newly merged PR code and history are fully present locally before deleting the feature branch.
  3. Preserve main (and Protected Branches): Only delete feature/task branches (such as //). Never delete main.
  4. Remote Reference Pruning: Prune stale remote tracking branches (git fetch --prune origin) to keep the remote tracking tree clean.
  5. Deep Garbage Collection: Prune unreachable reflog entries (git reflog expire --expire=now --all) and optimize the local object store (git gc --prune=now --aggressive) to keep the .git directory small, fast, and healthy.
  6. Zero Stale Branches: After cleanup, only main remains as the active local branch.

3. Step-by-Step Cleanup Runbook

When the human user requests post-merge cleanup, execute these exact steps in sequence:

Step 1: Verify Working Directory State

Ensure there are no unstaged modifications or stash conflicts:

git status

If dirty, stop and check if there are uncommitted files that need to be preserved.

Step 2: Switch to main and Pull Latest Upstream

Switch to the primary release branch and pull the merged changes from GitHub:

git switch main
git pull origin main

Step 3: Prune Remote Tracking Branches

Synchronize and remove remote branch references that were deleted on GitHub after PR merge:

git fetch --prune origin

Step 4: Identify & Delete Local Feature Branches

List all local branches to inspect what needs to be removed:

git branch

Delete all local feature branches (e.g. MishraShardendu22/main/):

# Safe delete merged branches:
git branch -d 

# If GitHub used Squash & Merge or Rebase & Merge (which changes commit hashes):
git branch -D 

Or delete all local branches except main in one command:

git branch | grep -v "^\* main$" | grep -v "^  main$" | xargs -r git branch -D

Step 5: Expire Reflogs & Run Aggressive Garbage Collection

Clean up dangling commits, unreachable objects, and optimize packfiles:

git reflog expire --expire=now --all
git gc --prune=now --aggressive

Step 6: Verify Final Repository State

Verify that only main remains and the working tree is clean:

git branch
git status

4. Automated CLI & Scripting Targets

To make cleanup and maintenance instantaneous, safe, and deterministic, use the dedicated scripts and Makefile targets:

# 1. Safe Local Sync & Merged Branch Cleanup
./scripts/git-sync-and-cleanup.sh --dry-run   # Preview branches to delete
./scripts/git-sync-and-cleanup.sh --force     # Synchronize main and delete merged branches
make git-sync-clean                           # Run local sync cleaner via Makefile

# 2. Deep Git Repository Maintenance & Garbage Collection
./scripts/git-maintenance.sh                  # Standard garbage collection and repack
./scripts/git-maintenance.sh --aggressive     # Aggressive compression (maximum space savings)
make git-gc                                   # Standard GC via Makefile
make git-maintain                             # Aggressive GC via Makefile

# 3. Automated Weekly Local Maintenance Setup
./scripts/git-maintenance.sh --install-cron   # Install weekly cron job (Sundays at 02:00 AM)
./scripts/git-maintenance.sh --status         # Check automated maintenance schedule and logs
make git-maintain-install                     # Install weekly maintenance cron via Makefile
make git-maintain-status                      # Inspect maintenance schedule status

5. Automated Remote Branch Cleanup on PR Merge

Remote feature branch deletion is fully automated via GitHub Actions:

  • Workflow: [.github/workflows/pr-branch-cleanup.yml](file:///home/ms22/Coding_stuff/Personal-Projects/github-backup-automation-system/.github/workflows/pr-branch-cleanup.yml)
  • Trigger: Triggers automatically on pull_request: [closed] when merged == true.
  • Action: Deletes the remote feature branch on GitHub, preventing stale remote reference buildup.

6. Summary Matrix for AI Agents & Humans

| Trigger Event | Automated / Allowed Action | Command(s) | | :--- | :--- | :--- | | PR Merged on GitHub | Automated (GitHub Actions) | .github/workflows/pr-branch-cleanup.yml deletes remote branch | | Local Stale Branch Cleanup | YES (On Demand / Scripted) | make git-sync-clean or ./scripts/git-sync-and-cleanup.sh --force | | Local Weekly Git GC & Optimization | Automated (Cron / On Demand) | make git-maintain-install or ./scripts/git-maintenance.sh | | Full Sync, Clean & GC | YES (Post-Merge) | make git-clean (./scripts/git-sync-and-cleanup.sh --force --gc) | | Unmerged Local Work Present | Stop & Warn User | Preserved automatically unless --force is specified |

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.