Skip to content
Back to skills

Setup Branch

ASecurity

Create branch, push to origin, optionally use worktree for dirty trees

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 10, 2026
businessgobashgit

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned September 10, 2026

npx -y skills add kapilvirenahuja/garura --skill setup-branch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Setup Branch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Setup Branch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/kapilvirenahuja-setup-branch/badge)](https://www.skillsdirectory.com/skills/kapilvirenahuja-setup-branch)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: setup-branch
description: Create branch, push to origin, optionally use worktree for dirty trees
user-invocable: false
model: haiku
allowed-tools: Bash, Read
---

# setup-branch

Model-invocable skill for creating and pushing branches.

## Purpose

Create a new branch from the current HEAD, push to origin with tracking, and handle dirty working trees via worktree or stash.

You DO the branch operations. You do NOT make decisions about branch naming — that comes from the caller.

## Input

Receive from agent:
- `branch_name` — Full branch name (e.g., `feature/42-add-oauth-login`)
- `issue_number` — Associated issue number (for reference only)
- `push_to_origin` — Whether to push (default: true)

## Process

### 1. Check Working Tree

```bash
git status --porcelain
```

Count changed files and lines to assess dirty state.

### 2. Check Branch Doesn't Exist

```bash
git branch --list "{branch_name}"
git ls-remote --heads origin "{branch_name}"
```

If branch exists locally or remotely, return error immediately.

### 3. Create Branch

**If clean tree:**

```bash
git checkout -b "{branch_name}"
```

**If dirty tree — assess scope:**

```bash
# Count changed files
git status --porcelain | wc -l
# Count changed lines
git diff --stat | tail -1
```

- **Minor changes** (≤5 files AND ≤100 lines): Stash, create branch, pop stash
  ```bash
  git stash push -m "garura: pre-branch stash for {branch_name}"
  git checkout -b "{branch_name}"
  git stash pop
  ```

- **Significant changes** (>5 files OR >100 lines): Use worktree
  ```bash
  git worktree add "../{repo-name}-{branch_slug}" -b "{branch_name}"
  ```

### 4. Push to Origin

If `push_to_origin` is true:

```bash
git push -u origin "{branch_name}"
```

### 5. Verify

```bash
git branch --show-current
git config --get branch.{branch_name}.remote
git config --get branch.{branch_name}.merge
```

## Output

Produce output using template: `templates/branch-output.md`

**IMPORTANT**: This skill produces operation results. The calling agent receives this output and decides what to do next. Do NOT instruct the agent to return or stop.

## Reference

Load branching conventions from: `reference/branching.md`

## Constraints

- NEVER force push
- NEVER delete existing branches
- NEVER modify existing branch content
- ALWAYS verify branch was created successfully before reporting
- ALWAYS check for existing branch before creating

## Version

| Field | Value |
|-------|-------|
| Version | 1.0.0 |
| Category | operations |

Files in this skill

  • SKILL.md2.5 KB
  • reference/branching.md1.6 KB
  • templates/branch-output.md1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.