Skip to main content
command CX Codex

push — Claude Code command: what it does, how to install

A Claude slash command that reads the branch and upstream state, then pushes — right away when the tree is clean.

MIT ★ 763 updated 2026-03-31

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/commands/push.md
Open on GitHub

What push does

One bash call reads the repo state: git status --porcelain=v1, the current branch with its tracking line, the remote URL, and the commits sitting ahead of upstream. A clean tree means the push goes out immediately, with no running commentary. On a fresh branch it switches to git push -u origin [branch-name].

Awkward situations get a stop instead of a guess. Fall behind the remote and you get a nudge toward git pull --rebase. Force pushing asks for confirmation first, diverged branches get a rebase-or-merge choice, and protected branches come with a reminder about pull requests. Harder cases can be handed to the git-expert subagent through the Task tool.

Drop the file at .claude/commands/push.md. The frontmatter allows Bash(git:*) and Task, and both are needed for the checks and the push itself. Uncommitted edits are not stashed or committed for you: with a dirty tree the push does not happen.

What it helps with

  • push a new branch and set its upstream
  • catch uncommitted edits before they block a push
  • handle a branch that has diverged from the remote
  • avoid an accidental force push
  • see which commits are about to leave your machine

Example prompts for the agent

  • /push this branch, but tell me which commits are going out first.
  • Run /push on feature/login; it has no upstream yet.
  • Use /push, and pick rebase if the branches have diverged.

How to install push

Manually: put the files in place

.claude/commands/push.md

Call it with /push. For all projects use ~/.claude/commands/

Questions about push

How do I install push in Claude Code?

Copy the command file to .claude/commands/push.md in your project. Then call /push.

What does push do?

It runs status, branch, remote and ahead-of-upstream checks, then pushes. If your branch is behind the remote, it stops and suggests git pull --rebase.

What does push need in order to work?

Bash(git:*) and Task allowed in the frontmatter, plus a repository with a remote set up, since the address is read through git remote -v.

Source text

push.md · MIT
---
description: Intelligently push commits to remote with safety checks and insights
category: workflow
allowed-tools: Bash(git:*), Task
---

Push commits to remote repository with appropriate safety checks and branch management.

## Git Expert Integration
For complex push scenarios (force push requirements, diverged branches, upstream conflicts, protected branch workflows), consider using the Task tool with `git-expert` subagent for specialized git expertise.

## Efficiency Note:
Be concise. Use single bash calls where possible. Skip verbose explanations and intermediate status messages. Execute the push directly if safe, show only the result.

## Instructions for Claude:

1. Run safety checks in a single bash call:
!git status --porcelain=v1 && echo "---" && git branch -vv | grep "^\*" && echo "---" && git remote -v | head -2 && echo "---" && git log --oneline @{u}..HEAD 2>/dev/null

Parse output to check:
- Any uncommitted changes (warn if present)
- Current branch and tracking info
- Remote repository URL
- Commits to be pushed

2. If safe to push (no uncommitted changes), execute push immediately:
   - For tracked branch: `git push`
   - For new branch: `git push -u origin [branch-name]`
   - If behind remote: Stop and suggest `git pull --rebase`

3. Show only the final result:
   - If successful: Show the push output with ✅ emoji and success message
   - If failed: Show error and suggest fix
   - If unsafe: Show what needs to be done first

4. Special cases to handle:
   - Diverged branches: Suggest rebase or merge strategy
   - No upstream branch: Use -u flag
   - Force push needed: Warn strongly, require confirmation
   - Protected branch: Remind about PR workflow

Example concise output:
- Skip: "Let me check if it's safe to push"
- Skip: "I'll analyze your branch status"
- Skip: "Ready to push X commits"
- Skip: "Executing push..."
- Just show the push result directly

© carlrannaberg · MIT · carlrannaberg/claudekit

Similar slash commands

All slash commands for Git and GitHub →

From the same set54

The whole set →

Project sponsors

Companies that keep this analytics open