AI Agent Git Workflows: Auto-Commit, Branch Creation & PR Generation
AI Agent Git Workflows: Auto-Commit, Branch Creation & PR Generation: Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Auto-generate semantic commit messages from git diff context
- Create feature branches and push changes without manual git commands
- Generate rich PR descriptions with context, test coverage, and risk assessment
- Detect and resolve simple merge conflicts autonomously
A Complete Git-Aware Agent Workflow
This workflow creates a branch, makes changes, commits with a meaningful message, and outputs a PR body:
import { createAgent } from 'smoke-monkey-harness';const agent = createAgent({provider: 'anthropic',model: 'claude-3-7-sonnet',workspacePath: process.cwd(),autoApprove: true,});await agent.run(`1. Create a new git branch: git checkout -b refactor/auth-async-await2. Refactor all Promise.then() chains in src/auth/ to use async/await.3. Run npx tsc --noEmit to validate no type errors were introduced.4. Run npm test -- --testPathPattern=auth to confirm tests pass.5. Stage all changes: git add -A6. Write a semantic commit message summarizing the changes and commit.7. Output a markdown PR description with: Summary, Changes Made, Test Coverage, and Risk Level.`);
Generating Semantic Commit Messages
Instruct the agent to follow the Conventional Commits specification for all commits it creates. This ensures commit history is machine-parseable for changelog generation and semantic versioning:
feat(auth): migrate Promise chains to async/awaitfix(payments): handle race condition in concurrent charge requestsrefactor(notifications): extract sendEmail into shared utilitytest(auth): add missing edge case tests for token refresh
The agent reads the actual diff and generates the appropriate type prefix, scope, and description automatically.
Frequently Asked Questions
Q:Can Smoke Monkey push branches to remote GitHub repositories?
Yes, via git push in the run_command tool. Ensure the workspace has GitHub credentials configured (SSH key or GitHub CLI token) and set run_command permission to auto for CI environments.
Q:How do I prevent the agent from committing to the main branch accidentally?
Instruct the agent to always create a new branch before making changes. Add a pre-commit hook that blocks commits directly to main/master as a safety net.
Related Alternatives & Comparisons
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.