gh) so agents can branch, commit, push, and open pull requests from a repo checkout.
Prerequisites: git installed with the working directory inside a repository (
github_create_branch, github_commit_and_push); origin remote configured for push; gh CLI installed and authenticated via gh auth login (github_create_pull_request).Quick Start
How It Works
Tools
github_create_branch(branch_name: str) -> str
Creates and checks out a new branch (git checkout -B).
| Parameter | Type | Description |
|---|---|---|
branch_name | str | Branch to create and check out |
github_commit_and_push(commit_message: str) -> str
Stages all changes, commits, and pushes to origin on the current branch.
| Parameter | Type | Description |
|---|---|---|
commit_message | str | Commit message |
"No changes to commit.", or an error string.
github_create_pull_request(title, body, head_branch, base_branch="main") -> str
Creates a pull request via gh pr create.
| Parameter | Type | Default | Description |
|---|---|---|---|
title | str | — | PR title in the GitHub UI — descriptive and concise |
body | str | — | PR description (markdown, issue refs such as #123) |
head_branch | str | — | Source branch with your changes |
base_branch | str | "main" | Target branch (main, master, develop, …) |
gh is missing or unauthenticated.
Common patterns
- Full PR flow
- Non-main base
- PR only
Best practices
Authenticate gh once
Authenticate gh once
Run
gh auth login before agents call github_create_pull_request. The tool checks gh auth status first.Keep commits scoped
Keep commits scoped
github_commit_and_push stages all changes (git add .). Review the working tree before the agent commits.Write descriptive PR bodies
Write descriptive PR bodies
Include what changed, why, and linked issues — the
body field supports markdown.Handle missing CLI gracefully
Handle missing CLI gracefully
Tools return error strings rather than raising — check return values in hooks if you need hard failures.
Related
Linear Bot
Example workflow using GitHub tools
Shell Tools
Similar CLI-wrapping tools

