← BLOG
Workflow

Automate Git Commits, Branches, and PRs with Claude Code

Git is essential but tedious. Claude Code automates commit messages, branch naming, and PR creation so you can spend your time on actual code.

Git takes up more time than most developers realize. Writing commit messages, naming branches, crafting PR descriptions, resolving merge conflicts. These tasks are necessary but low-value. Claude Code handles all of them, letting you focus on the code itself.

How does Claude Code automate commits?

Claude Code reads the diff, understands what changed and why, and writes a commit message that actually describes the changes. No more "fix stuff" or "update files."

bash
# Simple commit with auto-generated message
> "Commit my changes with a descriptive message"

# Conventional commits format
> "Commit using conventional commits format"
# → fix(auth): validate email format before password check

# Commit with context
> "Commit these changes — I fixed the race condition
   in the WebSocket handler"
# → fix(ws): eliminate race condition in message handler
#   by synchronizing connection state updates

How does Claude Code handle branches?

bash
# Create a well-named branch for your feature
> "Create a branch for adding OAuth2 login"
# → git checkout -b feat/oauth2-login

# Branch from a specific base
> "Create a branch for the hotfix from production"
# → git checkout -b hotfix/production-fix origin/main

How do you create PRs with Claude Code?

This is where Claude Code saves the most time. It reads all your commits, understands the full scope of changes, and writes a PR description that reviewers can actually use.

bash
# Complete PR flow
> "Push this branch and open a PR with a clear description"

# Claude Code will:
# 1. Push the branch to origin
# 2. Read the full diff
# 3. Write a PR title and description
# 4. Open the PR via GitHub CLI

# Review an existing PR
> "Review the PR at #42 and suggest improvements"

What does the complete automated workflow look like?

The real power is combining everything into a single prompt. One instruction, complete execution:

bash
# Complete workflow in one prompt:
> "Fix the validation bug in the login form, write a test
   for it, commit with a descriptive message, and open a PR"

# Claude Code executes:
# 1. Reads the codebase to find the login form
# 2. Identifies and fixes the validation bug
# 3. Writes a unit test for the fix
# 4. Runs the test suite to verify
# 5. Stages all changes
# 6. Writes a conventional commit message
# 7. Pushes the branch
# 8. Opens a PR with a full description

How do you configure git behavior in CLAUDE.md?

Add git conventions to your CLAUDE.md so Claude Code follows your team's standards consistently:

markdown
## Git Conventions
- Use conventional commits: feat:, fix:, chore:, docs:, refactor:
- Branch naming: feat/*, fix/*, hotfix/*, chore/*
- Always run tests before committing
- PR descriptions must include: Summary, Changes, Testing
- Never force-push to main or develop
TIP

Set up a pre-commit hook via Claude Code Hooks to auto-format and lint before every commit. This ensures Claude Code's commits always pass your team's quality gates.

Frequently asked questions

Does Claude Code need GitHub CLI installed?+
Yes. Claude Code uses `gh` (GitHub CLI) to create pull requests and interact with GitHub. Install it with `brew install gh` on macOS or follow GitHub's installation guide for your platform.
Can Claude Code resolve merge conflicts?+
Yes. Tell Claude Code about the conflict and it will read the conflicting files, understand both sides, and resolve the conflict based on the intent of each change. It works especially well when you describe which side should "win."
Does Claude Code work with GitLab or Bitbucket?+
Claude Code can run any git command, so basic operations work with any git hosting. For PR creation and issue management, it works best with GitHub via the gh CLI. GitLab and Bitbucket support is available through MCP integrations.
How do I prevent Claude Code from pushing to the wrong branch?+
Add branch protection rules to your CLAUDE.md: "Never push directly to main or develop. Always create a feature branch first." You can also use Claude Code's permission system to require approval before any git push command.
ALL POSTSSTART FREE COURSE →