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). user.email should match the identity you expect to author commits — the foreign-author guard reads git config user.email.Quick Start
1
Simple Usage
2
With Configuration
How It Works
You don’t have to think about branch safety — the tool quietly does the right thing, and only your tracked edits (plus any files you list inpaths) are committed — untracked files like a new .env or build output are never swept in.
User: “Commit and push what I have.”
Agent: (tool auto-creates praisonai/fix-login-a1b2c3, pushes there, and reports the branch name back)
Tools
github_create_branch(branch_name, repo_path=None) -> str
Creates and checks out a new branch (git checkout -B).
Returns a success message or an error string.
github_commit_and_push(commit_message, branch=None, allow_unsafe_branch=False, repo_path=None, paths=None) -> str
Stages tracked changes (plus any paths you list), commits, and pushes to origin — with branch-safety guardrails that refuse unsafe pushes and never force-push.
Returns a success message,
"No changes to commit.", or an error string. Untracked files alone don’t count as changes — list them in paths to commit them.
Branch-safety rules
The tool checks these rules before staging anything, so a refusal leaves your index and working tree untouched.- Agent branches are always allowed. Any branch whose name starts with
praisonai/skips the default and foreign-author checks. - The default branch is never pushed directly. On
main(or whenbranch="main"), the tool creates a freshpraisonai/{slug}-{6hex}branch from HEAD and pushes there instead. - Foreign commits are refused. If the target branch carries commits authored by someone other than your
git config user.email, the push stops. - Divergence is refused, never forced. If the remote branch is not an ancestor of HEAD, the push stops — this is never overridable.
- Override with care.
allow_unsafe_branch=True(or envPRAISONAI_GIT_ALLOW_UNSAFE_BRANCH=true) bypasses rules 2 and 3, but never rule 4.
github_create_pull_request(title, body, head_branch, base_branch="main", repo_path=None) -> str
Creates a pull request via gh pr create.
gh is missing or unauthenticated.
Common patterns
- Auto-branch (safest)
- Full PR flow
- Non-main base
- Specific repository
- Committing new files
- 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 only tracked changes (git add -u -- .). New (untracked) files are committed only when you list them in the paths argument — an untracked .env or build output is never swept in. Staging also runs after the branch-safety checks, so a refused push leaves the index untouched.Prefer the auto-branch flow
Prefer the auto-branch flow
Leaving
branch=None while on the default branch is the safest, one-line way to ship a change. The tool picks a praisonai/… name, pushes there, and reports the name in its return string.When to set allow_unsafe_branch
When to set allow_unsafe_branch
Only for a branch you own (e.g.
release/v2) that carries commits by someone other than the current committer — never for the default branch as a habit. Set env PRAISONAI_GIT_ALLOW_UNSAFE_BRANCH=true for CI. Divergence (force-push) is never allowed regardless.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

