Skip to main content
Glama

create-branch

Initiate and manage a new git branch from a specified repository, with options to define a starting point, switch to the branch, or force creation if it exists.

Instructions

Create a new git branch, optionally from a specific starting point.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
branchNameYesName of the new branch to create
forceNoForce create branch, resetting it if it already exists (-B flag)
repoPathYesAbsolute path to the git repository
startPointNoStarting point for new branch (commit, branch, or tag). Defaults to current HEAD
switchToBranchNoSwitch to the new branch after creation (default: true)

Implementation Reference

  • The private #handle method implements the core logic of the 'create-branch' tool, using simple-git to create a new branch with options for starting point, force, and checkout.
    readonly #handle: ToolCallback<typeof GIT_CREATE_BRANCH_INPUT_SCHEMA> = async (input) => {
    	const sg = simpleGit(input.repoPath);
    
    	const isRepo = await sg.checkIsRepo();
    	if (!isRepo) {
    		return {
    			isError: true,
    			content: [
    				{
    					type: 'text',
    					text: 'Not a git repository',
    				},
    			],
    		};
    	}
    
    	const startPoint = input.startPoint ?? 'HEAD';
    
    	// Force create branch with switch (equivalent to git checkout -B)
    	if (input.force && input.switchToBranch) {
    		await sg.checkout(['-B', input.branchName, startPoint]);
    		return {
    			content: [
    				{
    					type: 'text',
    					text: `Force created and switched to branch '${input.branchName}' from '${startPoint}'`,
    				},
    			],
    		};
    	}
    
    	// Force create branch without switch
    	if (input.force) {
    		const result = await sg.branch(['-B', input.branchName, startPoint]);
    		return {
    			content: [
    				{
    					type: 'text',
    					text: `Force created branch '${input.branchName}' from '${startPoint}'`,
    				},
    				{
    					type: 'text',
    					text: JSON.stringify(result),
    				},
    			],
    		};
    	}
    
    	// Regular branch creation with switch
    	if (input.switchToBranch) {
    		await (input.startPoint
    			? sg.checkoutBranch(input.branchName, input.startPoint)
    			: sg.checkoutLocalBranch(input.branchName));
    		return {
    			content: [
    				{
    					type: 'text',
    					text: `Created and switched to branch '${input.branchName}'${input.startPoint ? ` from '${input.startPoint}'` : ''}`,
    				},
    			],
    		};
    	}
    
    	// Regular branch creation without switch
    	const result = await sg.branch([input.branchName, startPoint]);
    
    	return {
    		content: [
    			{
    				type: 'text',
    				text: `Created branch '${input.branchName}' from '${startPoint}'`,
    			},
    			{
    				type: 'text',
    				text: JSON.stringify(result),
    			},
    		],
    	};
    };
  • Zod schema defining the input parameters for the create-branch tool.
    export const GIT_CREATE_BRANCH_INPUT_SCHEMA = {
    	repoPath: z.string().describe('Absolute path to the git repository'),
    	branchName: z.string().describe('Name of the new branch to create'),
    	startPoint: z
    		.string()
    		.optional()
    		.describe('Starting point for new branch (commit, branch, or tag). Defaults to current HEAD'),
    	switchToBranch: z
    		.boolean()
    		.optional()
    		.default(true)
    		.describe('Switch to the new branch after creation (default: true)'),
    	force: z.boolean().optional().describe('Force create branch, resetting it if it already exists (-B flag)'),
    };
  • The register method in GitCreateBranchTool class that registers the tool with the MCP server.
    register(srv: McpServer) {
    	srv.registerTool(this.name, this.config, this.#handle);
    }
  • Instantiation and registration call for the GitCreateBranchTool in the main server setup.
    new GitCreateBranchTool().register(server);
  • Getter returning the tool name 'create-branch'.
    get name() {
    	return 'create-branch';
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations indicate readOnlyHint=false, consistent with the 'create' action. The description adds minimal behavioral context beyond annotations—it mentions the optional starting point but doesn't cover error conditions, permissions needed, or what happens if the branch already exists (though 'force' parameter hints at this).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('Create a new git branch') and adds only essential optional detail. There is no wasted verbiage or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the mutation nature (readOnlyHint=false) and lack of output schema, the description is minimally adequate but lacks details on return values, error handling, or integration with sibling tools. It covers the basic purpose but leaves gaps for effective agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 5 parameters. The description adds no additional parameter semantics beyond what's in the schema, such as format examples or constraints, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Create') and resource ('new git branch') with optional starting point specification. It distinguishes from siblings like 'checkout' or 'reset' by focusing on branch creation, though it doesn't explicitly contrast with them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'checkout' for switching branches or 'init' for repository setup. It mentions the optional starting point but offers no context about prerequisites or typical workflows.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ver0-project/mcps'

If you have feedback or need assistance with the MCP directory API, please join our Discord server