setup-branch
Create a new branch and worktree from a JIRA ID or URL. Determines branch prefix (fix/ or feat/) from the JIRA item type, sets up the worktree one level up, and installs dependencies.
How do I install this agent skill?
npx skills add https://github.com/morphet81/cheat-sheets --skill setup-branchIs this agent skill safe to install?
- Gen Agent Trust Hubwarn
The skill automates git worktree setup and environment configuration based on JIRA tickets. While it provides useful developer automation, it presents security risks due to the interpolation of user-provided input directly into shell commands, the automatic execution of package manager install scripts, and the handling of sensitive .env files.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
- ZeroLeakspass
Score: 93/100 · 2 sections analyzed
What does this agent skill do?
Create a new git branch and worktree from a JIRA ticket. Automatically names the branch based on the JIRA item type and sets up the worktree ready to work in.
Usage:
/setup-branch PROJ-123- Create branch from JIRA ID/setup-branch https://mycompany.atlassian.net/browse/PROJ-123- Create branch from JIRA URL
Instructions:
-
Check prerequisites:
- Atlassian CLI (
acli): Runacli auth statusto check if the CLI is installed and authenticated.- If the command is not found, display the following message and STOP:
## Missing Prerequisite: Atlassian CLI The `acli` command is not installed. This skill requires the Atlassian CLI to fetch JIRA issue details. Install it with: brew tap atlassian/acli && brew install acli - If the command fails with an authentication error, display the following message and STOP:
## Missing Prerequisite: Atlassian CLI Authentication The Atlassian CLI is not authenticated. Please run `acli auth login` to authenticate before using this skill.
- If the command is not found, display the following message and STOP:
- GitHub CLI (
gh): Rungh --versionto check if theghCLI is installed. If the command fails (not found), display the following message and STOP:## Missing Prerequisite: GitHub CLI The `gh` command is not installed. This skill requires the GitHub CLI for repository operations. Install it from: https://cli.github.com/ - GitHub CLI authentication: Run
gh auth statusto check ifghis authenticated. If the command indicates the user is not logged in, display the following message and STOP:## Missing Prerequisite: GitHub CLI Authentication The GitHub CLI is not authenticated. Please run `gh auth login` to authenticate before using this skill.
- Atlassian CLI (
-
Parse the JIRA reference from $ARGUMENTS:
- If no argument is provided, inform the user of the expected usage and STOP
- If the argument is a URL (contains
atlassian.net/browse/or similar), extract the JIRA ID from the URL path (e.g.,https://mycompany.atlassian.net/browse/PROJ-123→PROJ-123). If the JIRA ID cannot be extracted, show what was received and STOP - If the argument is already a JIRA ID (matches pattern like
PROJ-123,ABC-1, etc.), use it directly - If the argument cannot be parsed as either a URL or JIRA ID, inform the user and STOP
-
Fetch the JIRA item type:
- Use the Atlassian CLI to fetch the issue details for the extracted JIRA ID:
acli jira workitem view <JIRA-ID> --fields issuetype --json - Identify the issue type (Bug, Story, Task, Epic, Sub-task, etc.)
- If the fetch fails, ask the developer to provide the issue type manually using
AskUserQuestionwith options: "Bug", "Story/Task/Other"
- Use the Atlassian CLI to fetch the issue details for the extracted JIRA ID:
-
Determine the branch name:
- Lowercase the JIRA ID for use in the branch name (e.g.,
PROJ-123→proj-123) - If the issue type is Bug: branch name is
fix/<jira-id>(e.g.,fix/proj-123) - For all other types (Story, Task, Epic, Sub-task, etc.): branch name is
feat/<jira-id>(e.g.,feat/proj-123)
- Lowercase the JIRA ID for use in the branch name (e.g.,
-
Ask which base branch to branch from:
- Run
git branch --show-currentto get the current working directory's branch name - Use
AskUserQuestionto ask the developer which branch to use as the base - The first (default) option should be the current branch name (e.g., if you're on
develop, suggestdevelop) - If the current branch is different from
main, includemainas a second option - Let the developer type a different branch name via the "Other" option
- Run
-
Fetch the base branch from remote:
- Run
git fetch origin <base-branch> - If the fetch fails (e.g., the base branch does not exist on the remote), show the error and STOP immediately. Do not continue with branch or worktree creation.
- Do NOT checkout or pull the base branch — this avoids disrupting uncommitted work in the current worktree.
- Run
-
Create the new branch and worktree together:
- If the branch name already exists locally (
git rev-parse --verify <branch-name>succeeds), inform the user and STOP (do not force-create) - Determine the worktree path: take the parent directory of the current working directory and append the branch name with
/replaced by-- Example: if CWD is
/Users/dev/my-projectand branch isfix/proj-123, the worktree path is/Users/dev/fix-proj-123
- Example: if CWD is
- If the worktree directory already exists, inform the user and STOP
- Run
git worktree add <worktree-path> -b <branch-name> origin/<base-branch>- This creates the new branch based on the remote base branch AND the worktree in a single command, without touching the current worktree
- If the command fails, show the error and STOP
- If the branch name already exists locally (
-
Install dependencies in the new worktree:
- All commands in this step must run from the new worktree directory (use
cd <worktree-path>before running them, or pass thecwdoption) - Detect the package manager by checking for lock files in the new worktree directory:
bun.lockborbun.lock→ runbun install --frozen-lockfilepnpm-lock.yaml→ runpnpm install --frozen-lockfileyarn.lock→ runyarn install --frozen-lockfilepackage-lock.json→ runnpm ci- If none of these lock files exist but a
package.jsonis present → runnpm installand warn that no lock file was found - If no
package.jsonexists → skip dependency installation entirely
- If the install command fails, show the error but do NOT delete the worktree — the developer may want to fix the issue manually
- All commands in this step must run from the new worktree directory (use
-
Trust mise configuration:
- Run
mise trustfrom the new worktree directory to trust any.mise.tomlor.tool-versionsfile present - If
miseis not installed (command not found), skip this step silently - If the command fails for any other reason, show a warning but continue
- Run
-
Copy
.envfile to the new worktree:
- Check if a
.envfile exists in the current working directory - If it exists, copy it to the root of the new worktree directory (
cp .env <worktree-path>/.env) - If it does not exist, skip this step silently
- Create
.agentfile in the new worktree:
- Write a simple config file at
<worktree-path>/.agentcontaining the base branch name:baseBranch=<base-branch> - Example: if the base branch is
main, the file contents would bebaseBranch=main
- Show success message:
Display a summary with all relevant information:
## Branch Setup Complete
- JIRA: PROJ-123
- Type: Bug → fix/proj-123
- Base: origin/main
- Worktree: /Users/dev/fix-proj-123
- Dependencies: installed (npm ci)
To start working:
cd /Users/dev/fix-proj-123
To push for the first time:
git push -u origin fix/proj-123
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/morphet81/cheat-sheets/setup-branch">View setup-branch on skillZs</a>