Get the FREE Ultimate OpenClaw Setup Guide →

git-branch

npx machina-cli add skill puku0x/agent-skills-test/git-branch --openclaw
Files (1)
SKILL.md
2.7 KB

Git Branch Skill

This skill guides the creation of Git branches with project-specific naming conventions.

When to Use

Use this skill when:

  • You have made changes to the codebase and need to create a new branch for those changes.
  • You want to ensure that the branch name follows the project's naming conventions.

Instructions

Step 1: Check staged changes

Use the following command to view staged changes:

git diff --staged

Important If there are staged changes, proceed to the next step.

If there are no staged changes, check unstaged changes with:

git diff --name-only

Step 2: Determine branch type and description

The format for branch names is:

<type>-<description>
  • If there are only staged changes, base the branch name on the staged changes.
  • If there are only unstaged changes, base the branch name on the unstaged changes.
  • If there are both staged and unstaged changes, base the branch name on the staged changes.

type is determined based on the patterns of the changed files:

  • feat-: New features or changes to existing features
  • fix-: Bug fixes
  • refactor-: Refactoring (changes that do not add features or fix bugs)
  • test-: Adding or modifying tests (e.g., changes to *.spec.* or *.spec.*.snap files)
  • docs-: Documentation-only changes (e.g., changes to *.md files)
  • ci-: CI-related changes (e.g., changes to files in .github/workflows/* or .github/actions/*)
  • chore-: Other changes (e.g., changes to *.json, configuration files like *.config.js, .gitignore, etc.)
  • revert-: Reverting previous commits
  • build-: Changes related to the build system or external dependencies
  • perf-: Performance improvements

description should concisely describe the changes made, using hyphens to separate words.

Step 3: Create the branch

Use git switch -c to create and switch to the new branch.

Example:

git switch -c feat-user-authentication

[!NOTE]

When the name of the branch already exists, append a unique suffix to the branch name to avoid conflicts. For example, if feat-user-authentication already exists, create feat-user-authentication-1, feat-user-authentication-2, etc.

References

Source

git clone https://github.com/puku0x/agent-skills-test/blob/main/.github/skills/git-branch/SKILL.mdView on GitHub

Overview

This skill creates Git branches using project naming conventions. It detects the branch type from changed files (feat, fix, docs, refactor, test, build, ci, chore, revert, perf) and builds a hyphenated description, choosing between staged or unstaged changes as the basis.

How This Skill Works

The tool inspects staged changes with git diff --staged. If none are staged, it checks for unstaged changes using git diff --name-only. It determines the type from file patterns, constructs a branch name in the format <type>-<description>, and creates the branch with git switch -c. If the name already exists, it appends a numeric suffix to avoid conflicts.

When to Use It

  • You have staged changes and want to create a new branch following naming conventions
  • You have unstaged changes and want to snapshot them into a branch
  • Both staged and unstaged changes exist and you want to base the name on staged changes
  • You need a branch name that reflects the change type (feat, fix, docs, etc.)
  • You are making feature, bug fix, documentation, test, or CI related changes

Quick Start

  1. Step 1: git diff --staged
  2. Step 2: Determine type and description from the changes
  3. Step 3: git switch -c <type>-<description> (applying a suffix if needed)

Best Practices

  • Base the branch on staged changes when possible to lock in intentional edits
  • Keep the description concise and hyphenated (no spaces)
  • Validate the type against changed file patterns before finalizing
  • If a branch name exists, append a unique suffix (e.g., -1, -2)
  • Align branch names with the project's established conventions

Example Use Cases

  • feat-user-authentication
  • fix-payment-validation-bug
  • docs-readme-update-strategies
  • test-login-flow-spec
  • ci-update-workflows

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers