Checkout Branch Skill
This skill helps you create and checkout a new git branch following conventional naming conventions.
Instructions
When the user asks to create a branch or start working on a task, follow these steps:
1. Understand the Task
If the user provides a clear task description, use it directly. If not, use the AskUserQuestion tool to ask:
- What task are they working on?
- What type of work is it? (feature, fix, chore, etc.)
2. Determine the Branch Type
Analyze the task description to determine the appropriate type:
feat: New features or enhancements
- Keywords: "add", "create", "implement", "build", "new feature"
- Examples: "add user authentication", "implement dark mode"
fix: Bug fixes
- Keywords: "fix", "resolve", "bug", "issue", "patch"
- Examples: "fix memory leak", "resolve login error"
chore: Maintenance, dependencies, tooling, configuration
- Keywords: "update dependencies", "configure", "setup", "maintain"
- Examples: "update npm packages", "configure eslint"
docs: Documentation changes
- Keywords: "document", "readme", "docs", "documentation"
- Examples: "update API docs", "add setup instructions"
refactor: Code restructuring without changing behavior
- Keywords: "refactor", "restructure", "reorganize", "simplify"
- Examples: "refactor auth logic", "simplify error handling"
test: Adding or updating tests
- Keywords: "test", "testing", "unit test", "integration test"
- Examples: "add unit tests", "update test coverage"
style: Code formatting and style changes
- Keywords: "format", "style", "lint", "prettier"
- Examples: "format components", "apply linting rules"
perf: Performance improvements
- Keywords: "optimize", "performance", "speed up", "improve performance"
- Examples: "optimize queries", "reduce bundle size"
ci: CI/CD pipeline changes
- Keywords: "ci", "pipeline", "workflow", "github actions"
- Examples: "add github actions", "update deploy workflow"
security: Security fixes and improvements
- Keywords: "security", "vulnerability", "secure", "auth"
- Examples: "fix xss vulnerability", "improve authentication"
3. Generate Branch Name
Convert the task description to a branch name following these rules:
- Lowercase: Convert all characters to lowercase
- Kebab-case: Replace spaces with hyphens
- Remove special characters: Keep only letters, numbers, and hyphens
- Trim: Remove leading/trailing hyphens
- Format: Use pattern
<type>/<description>
Examples:
- "Add user authentication" →
feat/add-user-authentication
- "Fix memory leak in parser" →
fix/memory-leak-in-parser
- "Update API Documentation!" →
docs/update-api-documentation
- "Refactor: error handling" →
refactor/error-handling
4. Check Current Branch Status
Before creating the branch, check the current status:
git status
If there are uncommitted changes, warn the user and ask if they want to:
- Commit the changes first
- Stash the changes
- Continue anyway (changes will carry over to the new branch)
5. Create and Checkout the Branch
Create and checkout the new branch:
git checkout -b <branch-name>
6. Confirm Success
After creating the branch:
- Verify with
git branch or git status
- Inform the user of the branch name
- Confirm they're ready to start working
Best Practices
- Be descriptive: Branch names should clearly indicate the work being done
- Be concise: Keep names under 50 characters when possible
- Consistent format: Always use
<type>/<description> pattern
- Check for conflicts: Ensure branch name doesn't already exist
- Clean branches: Remind users to delete branches after merging
Examples
Example 1: User provides clear description
User: "Create a branch to add user authentication"
Assistant: I'll create a new branch for adding user authentication.
Command: git checkout -b feat/add-user-authentication
Output: Switched to a new branch 'feat/add-user-authentication'
Response: "Created and checked out branch 'feat/add-user-authentication'. You're ready to start working on user authentication!"
Example 2: User needs clarification
User: "Create a new branch"
Assistant: [Uses AskUserQuestion to ask what task they're working on]
User: "I need to fix a bug in the login form"
Assistant: I'll create a new branch for fixing the login form bug.
Command: git checkout -b fix/login-form-bug
Output: Switched to a new branch 'fix/login-form-bug'
Response: "Created and checked out branch 'fix/login-form-bug'. Ready to fix the bug!"
Example 3: Uncommitted changes
User: "Create a branch to refactor the database layer"
Assistant: [Runs git status and sees uncommitted changes]
Response: "You have uncommitted changes. Would you like to commit them first, stash them, or continue anyway?"
User: "Commit them first"
Assistant: [Uses commit skill to commit changes, then creates branch]
Command: git checkout -b refactor/database-layer
Response: "Committed changes and created branch 'refactor/database-layer'."
Error Handling
- Branch already exists: Inform user and ask if they want to checkout the existing branch or choose a different name
- Not a git repository: Inform user they need to initialize a git repository first
- Uncommitted changes: Warn and provide options as described above
- Invalid characters: Clean the branch name by removing invalid characters
After Creating the Branch
Optionally suggest next steps:
- "Would you like me to help you implement [task]?"
- "Should I create a commit plan for this work?"
- "Need help getting started with this task?"
1---2name: checkout-branch3description: Create and checkout a new git branch with conventional naming based on the task description. Use when the user asks to create a branch, start working on a feature/fix, or begin a new task.4---5
6# Checkout Branch Skill
7
8This skill helps you create and checkout a new git branch following conventional naming conventions.
9
10## Instructions
11
12When the user asks to create a branch or start working on a task, follow these steps:
13
14### 1. Understand the Task
15
16If the user provides a clear task description, use it directly. If not, use the AskUserQuestion tool to ask:
17- What task are they working on?
18- What type of work is it? (feature, fix, chore, etc.)
19
20### 2. Determine the Branch Type
21
22Analyze the task description to determine the appropriate type:
23
24- **feat**: New features or enhancements
25 - Keywords: "add", "create", "implement", "build", "new feature"
26 - Examples: "add user authentication", "implement dark mode"
27
28- **fix**: Bug fixes
29 - Keywords: "fix", "resolve", "bug", "issue", "patch"
30 - Examples: "fix memory leak", "resolve login error"
31
32- **chore**: Maintenance, dependencies, tooling, configuration
33 - Keywords: "update dependencies", "configure", "setup", "maintain"
34 - Examples: "update npm packages", "configure eslint"
35
36- **docs**: Documentation changes
37 - Keywords: "document", "readme", "docs", "documentation"
38 - Examples: "update API docs", "add setup instructions"
39
40- **refactor**: Code restructuring without changing behavior
41 - Keywords: "refactor", "restructure", "reorganize", "simplify"
42 - Examples: "refactor auth logic", "simplify error handling"
43
44- **test**: Adding or updating tests
45 - Keywords: "test", "testing", "unit test", "integration test"
46 - Examples: "add unit tests", "update test coverage"
47
48- **style**: Code formatting and style changes
49 - Keywords: "format", "style", "lint", "prettier"
50 - Examples: "format components", "apply linting rules"
51
52- **perf**: Performance improvements
53 - Keywords: "optimize", "performance", "speed up", "improve performance"
54 - Examples: "optimize queries", "reduce bundle size"
55
56- **ci**: CI/CD pipeline changes
57 - Keywords: "ci", "pipeline", "workflow", "github actions"
58 - Examples: "add github actions", "update deploy workflow"
59
60- **security**: Security fixes and improvements
61 - Keywords: "security", "vulnerability", "secure", "auth"
62 - Examples: "fix xss vulnerability", "improve authentication"
63
64### 3. Generate Branch Name
65
66Convert the task description to a branch name following these rules:
67
681. **Lowercase**: Convert all characters to lowercase
692. **Kebab-case**: Replace spaces with hyphens
703. **Remove special characters**: Keep only letters, numbers, and hyphens
714. **Trim**: Remove leading/trailing hyphens
725. **Format**: Use pattern `<type>/<description>`
73
74Examples:
75- "Add user authentication" → `feat/add-user-authentication`
76- "Fix memory leak in parser" → `fix/memory-leak-in-parser`
77- "Update API Documentation!" → `docs/update-api-documentation`
78- "Refactor: error handling" → `refactor/error-handling`
79
80### 4. Check Current Branch Status
81
82Before creating the branch, check the current status:
83```bash
84git status
85```
86
87If there are uncommitted changes, warn the user and ask if they want to:
88- Commit the changes first
89- Stash the changes
90- Continue anyway (changes will carry over to the new branch)
91
92### 5. Create and Checkout the Branch
93
94Create and checkout the new branch:
95```bash
96git checkout -b <branch-name>
97```
98
99### 6. Confirm Success
100
101After creating the branch:
1021. Verify with `git branch` or `git status`
1032. Inform the user of the branch name
1043. Confirm they're ready to start working
105
106## Best Practices
107
108- **Be descriptive**: Branch names should clearly indicate the work being done
109- **Be concise**: Keep names under 50 characters when possible
110- **Consistent format**: Always use `<type>/<description>` pattern
111- **Check for conflicts**: Ensure branch name doesn't already exist
112- **Clean branches**: Remind users to delete branches after merging
113
114## Examples
115
116### Example 1: User provides clear description
117```
118User: "Create a branch to add user authentication"
119Assistant: I'll create a new branch for adding user authentication.
120Command: git checkout -b feat/add-user-authentication
121Output: Switched to a new branch 'feat/add-user-authentication'
122Response: "Created and checked out branch 'feat/add-user-authentication'. You're ready to start working on user authentication!"
123```
124
125### Example 2: User needs clarification
126```
127User: "Create a new branch"
128Assistant: [Uses AskUserQuestion to ask what task they're working on]
129User: "I need to fix a bug in the login form"
130Assistant: I'll create a new branch for fixing the login form bug.
131Command: git checkout -b fix/login-form-bug
132Output: Switched to a new branch 'fix/login-form-bug'
133Response: "Created and checked out branch 'fix/login-form-bug'. Ready to fix the bug!"
134```
135
136### Example 3: Uncommitted changes
137```
138User: "Create a branch to refactor the database layer"
139Assistant: [Runs git status and sees uncommitted changes]
140Response: "You have uncommitted changes. Would you like to commit them first, stash them, or continue anyway?"
141User: "Commit them first"
142Assistant: [Uses commit skill to commit changes, then creates branch]
143Command: git checkout -b refactor/database-layer
144Response: "Committed changes and created branch 'refactor/database-layer'."
145```
146
147## Error Handling
148
149- **Branch already exists**: Inform user and ask if they want to checkout the existing branch or choose a different name
150- **Not a git repository**: Inform user they need to initialize a git repository first
151- **Uncommitted changes**: Warn and provide options as described above
152- **Invalid characters**: Clean the branch name by removing invalid characters
153
154## After Creating the Branch
155
156Optionally suggest next steps:
157- "Would you like me to help you implement [task]?"
158- "Should I create a commit plan for this work?"
159- "Need help getting started with this task?"