Claude Code Git & Source Control: Commits, Co-Authored-By

AI, Devops & Infrastructure, Git, and Tutorials

Claude Code Git & Source Control: Commits, Co-Authored-By

Claude Code turns your terminal into a Git-aware coding partner. It reads your repository history, understands diffs, generates context-aware commit messages, resolves merge conflicts, and creates pull requests β€” all through natural language. This guide covers the practical Git and source control operations you can perform with Claude Code, from everyday commits to worktrees and GitHub automation, how the Co-Authored-By: Claude attribution works (and how to change or remove it), and how to connect everything to an automated deployment pipeline with DeployHQ.

In short: Claude Code drives your local git binary β€” there is no separate Git plugin to install. Ask in plain English (commit these changes, resolve this conflict, open a PR) and it runs real Git commands that respect your .gitconfig and hooks. By default, commits get a Co-Authored-By trailer naming the Claude model that made them. To remove it, set "attribution": false in ~/.claude/settings.json (older versions: set attribution.commit and attribution.pr to empty strings). The old includeCoAuthoredBy key is deprecated.

If you are new to the tool itself, start with our Claude Code setup walkthrough before reading on β€” this guide assumes Claude Code is already installed and authenticated. Keep our Claude Code cheatsheet open alongside for a single-page reference to slash commands, hooks, and MCP patterns.

What Git Is, and Why Claude Code Uses It

Git is the version control (source control) system that records every change to your project as a series of commits β€” saved snapshots with a message describing what changed and why. When Claude Code says it will commit changes, it means it will stage the files it edited and record a commit in your local repository, exactly as git add and git commit would. Nothing reaches GitHub, GitLab, or Bitbucket until a git push. If terms like staging, remote, or HEAD are unfamiliar, our Git glossary explains each one in a sentence or two.

Git itself is optional for Claude Code, but almost every workflow in this guide depends on it, and Claude's built-in commit and pull request instructions only matter inside a Git repository. If git --version fails on your machine, follow our step-by-step Git install guide first.

On native Windows, Git for Windows is recommended rather than required: it provides Git Bash, which Claude Code's Bash tool uses. Without it, Claude Code falls back to its PowerShell tool for shell commands. WSL setups don't need Git for Windows.

Setting Up Git with Claude Code

Install Claude Code

Anthropic's recommended install is the native installer, which updates itself in the background:

# macOS, Linux, WSL
curl -fsSL https://claude.ai/install.sh | bash
# Windows PowerShell
irm https://claude.ai/install.ps1 | iex

Homebrew (brew install --cask claude-code) and WinGet (winget install Anthropic.ClaudeCode) also work but don't auto-update by default. The npm package (npm install -g @anthropic-ai/claude-code) is still available and requires Node.js 22 or later.

Authenticate and Verify Git Integration

Launch Claude Code in your terminal inside any Git repository:

cd /path/to/your/project
claude

Follow the prompts to authenticate. Once inside, verify Git integration works by typing a natural language request:

Show me what files have changed

When a conversation starts, Claude Code gives Claude a Git status snapshot of the repository β€” the current branch, the main branch, git status output, and recent commits β€” so it already has context before you ask anything. No additional Git configuration is required; if git is on your PATH, Claude Code will use it.

What Claude Code Actually Calls

Under the hood, every natural language Git operation maps to a real shell invocation. Claude Code is not reimplementing Git β€” it runs your local git binary. The implications:

  • Your .gitconfig is respected. Custom aliases, signing keys, default branch names, and user.email apply to every commit Claude makes
  • Hooks fire normally. pre-commit, commit-msg, pre-push β€” Claude's commits go through your installed hooks. A misbehaving hook will block Claude the same way it would block you
  • safe.directory matters. If you work in mounted drives, dev containers, or shared filesystems, Git's safe-directory protection applies to Claude too
  • Permission rules gate risky commands. You can make Claude ask before every push by adding "ask": ["Bash(git push *)"] under permissions in .claude/settings.json, while still letting it commit locally without prompts

This is also why most Claude won't commit issues turn out to be ordinary Git config problems β€” a missing user.email, a stale GPG key, or a pre-commit hook rejecting the staged diff.

If your team already has its own commit and PR conventions packaged as skills, you can remove Claude Code's built-in commit/PR instructions and the Git status snapshot with "includeGitInstructions": false (or the CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS environment variable for a single session).

Essential Git Operations with Claude Code

This is where Claude Code shines in day-to-day development. Rather than memorising flags and options, you describe what you want in plain English. Keep our Git commands reference handy if you want to check what Claude is running on your behalf.

Creating Commits

Claude analyses your staged changes and recent commit history to generate messages that match your project's conventions. A few example prompts:

  • Commit these auth changes β€” Claude inspects the diff, identifies it as authentication-related, and writes a descriptive message
  • Create a commit following conventional commits β€” Claude formats the message as feat:, fix:, refactor:, etc., based on the actual changes
  • Commit with a detailed body explaining the security implications β€” Claude adds a multi-line body explaining why the change was made

If you use Conventional Commits, add a rule to your project's CLAUDE.md file and Claude will follow that format for every commit.

Resolving Merge Conflicts

Instead of manually editing conflict markers, describe the situation:

  • Help me resolve these merge conflicts on the feature branch β€” Claude reads the conflicting files, understands both sides, and proposes a resolution
  • Resolve the conflicts in src/auth.ts keeping our version of the login timeout β€” Claude applies your preference while integrating non-conflicting changes from the other branch
  • Show me what's conflicting and explain each conflict β€” Claude breaks down each conflict with context about what each side changed and why

Claude handles rebase conflicts the same way: if conflicts arise at any step of a rebase, you can ask Claude to resolve them while preserving the intent of both change sets.

Managing Branches

Branch operations become conversational:

  • Create a feature branch for the new payment integration β€” Claude runs git checkout -b feature/payment-integration (or your team's naming convention if specified in CLAUDE.md)
  • Which branches have unmerged work? β€” Claude lists branches with their last commit dates and descriptions
  • Delete all branches that have been merged into main β€” Claude identifies safe-to-delete branches and removes them
  • Switch to the branch that has the auth refactor β€” Claude finds the right branch by searching commit messages and branch names

Teams adopting one of the common Git branching strategies (Gitflow, trunk-based, environment branches) should document the convention in CLAUDE.md so Claude follows it consistently for every new branch.

Don't confuse Git branches with the /branch slash command: /branch forks the conversation so you can try a different direction, and has nothing to do with your repository's branches.

Working with Pull Requests

For GitHub, Claude Code uses the GitHub CLI (gh) to create and manage pull requests:

  • Create a PR for this feature branch with a summary of changes β€” Claude analyses all commits on the branch, generates a title and description covering the what and why, and opens the PR
  • Update the PR description with the latest changes β€” Claude amends the description after additional commits
  • What feedback is on my open PR? β€” Claude fetches review comments and summarises them

A few built-in commands help around PRs:

  • /code-review (alias /review) reviews the current diff, or a PR number, branch, or path you pass, for correctness bugs
  • /security-review analyses the changes on your current branch against origin's default branch for vulnerabilities such as injection or auth issues
  • claude --from-pr 1234 opens the session picker filtered to sessions linked to a specific pull request, so you can pick up review feedback where you left off

For how these compare with dedicated review bots, see our AI code review tools comparison. For tips on structuring effective PRs, see our guide to the perfect pull request.

Searching Git History

Git archaeology is one of Claude Code's strongest capabilities:

  • Find when the login timeout was changed from 30 minutes to 15 β€” Claude searches through commit diffs to pinpoint the exact commit
  • What commits touched the auth module this week? β€” Claude filters history by path and date range
  • Why was the caching layer redesigned in v2.1? β€” Claude reads commits, PR descriptions, and code comments to reconstruct the reasoning
  • Who changed the deployment config last and what did they change? β€” Claude traces authorship through git log and git blame
  • What changes made it into the v1.2.3 release? β€” Claude compares tags and summarises the changelog

For very large repositories, narrow the search with a path or commit range in your prompt (…in `src/billing/` over the last 30 days) so Claude doesn't burn context grepping the whole tree.

Rebasing and Cherry-Picking

For more advanced Git workflows:

  • Rebase this branch onto main and squash the WIP commits β€” Claude performs the rebase, identifies which commits are work-in-progress, and squashes them into logical units
  • Cherry-pick the database migration fix from the hotfix branch β€” Claude identifies the specific commit and applies it to your current branch
  • Clean up my commit history before merging β€” squash the fixup commits β€” Claude rewrites the branch history, combining related commits

Checkpoints Are Not a Substitute for Git

Claude Code's /rewind (aliases /checkpoint, /undo) can roll back the conversation and the files Claude edited with its own file tools. It does not track files that only a Bash command changed, and it isn't permanent history. Anthropic's own docs describe checkpoints as session-level recovery that works alongside Git rather than replacing it β€” commit early and often, and use /rewind for quick undo that last attempt moments.

Advanced Git Workflows

Git Worktrees with Claude Code

Git worktrees let you check out multiple branches simultaneously in separate directories. Claude Code has first-class worktree support:

claude --worktree feature-auth   # or: claude -w feature-auth

This creates an isolated checkout under .claude/worktrees/feature-auth/ on a new branch named worktree-feature-auth and starts Claude inside it. Run the same command with a different name in a second terminal and you have two sessions editing the same repository without colliding. You can also ask Claude mid-session to work in a worktree and it will create one for you.

Three practical gotchas from the docs:

  • Add .claude/worktrees/ to .gitignore so worktree contents don't show up as untracked files in your main checkout
  • A worktree is a fresh checkout β€” gitignored files like .env aren't there and dependencies aren't installed. List the gitignored files you need copied in a .worktreeinclude file at the repo root
  • Clean up -p runs yourself. A claude -p --worktree run exits without asking, so remove leftovers with git worktree remove <path>

Worktrees also pair well with running Claude Code headless in CI and in parallel β€” one session per worktree β€” so a long-running task in one branch doesn't block a hotfix in another.

GitHub Actions Integration

Claude Code can help you write, debug, and optimise CI workflows, and it can also run inside them:

  • Run /install-github-app in your repository to install the Claude GitHub App, add the authentication secret, and open a PR with the workflow file. After you merge it, mentioning @claude in an issue or PR comment triggers Claude in your Actions runner. This command works only with github.com repositories; GitLab has its own CI/CD integration
  • Create a GitHub Actions workflow that runs tests on push β€” Claude generates a .github/workflows/*.yml with proper job dependencies
  • Why is the CI pipeline failing? β€” Claude reads the workflow file alongside recent error logs to diagnose issues

GitHub Actions is good at running tests and builds; shipping files to your own servers with release tracking and rollbacks is a different job. If you are weighing whether to deploy straight from Actions, our DeployHQ vs GitHub Actions comparison breaks down where each fits, and our walkthrough of AI agents in CI/CD pipelines, from GitHub issue to production deploy shows the end-to-end flow.

Understanding Co-Authored-By Attribution

When Claude Code creates a commit on your behalf, it adds a Git trailer to the commit message by default. In current versions the trailer names the model that made the commit:

fix: resolve authentication bug in login flow

Fixes the issue where users were being logged out unexpectedly
after session timeout.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

The exact name follows the model in use (or the subagent's model, if a subagent made the commit). If Claude Code can't confirm the exact model version it writes plain Claude, and for a non-Claude model behind a custom ANTHROPIC_BASE_URL it writes Claude Code. Pull requests Claude opens get a separate plain-text line in the description: Generated with [Claude Code](https://claude.com/claude-code), prefixed with a robot emoji.

Sessions started in the cloud or via Remote Control add one more thing: a Claude-Session trailer on commits (and a link in PR descriptions) pointing back to the claude.ai session.

GitHub recognises the Co-authored-by: trailer format and lists co-authors on the commit. Note that GitHub only credits a co-author when the trailer's email is associated with a GitHub account.

The Case for Keeping Attribution

Transparency and accountability. Many organisations value knowing how their code was written. The attribution creates a clear audit trail β€” and because the trailer now names the model, you can see which model produced a change when you look back at an incident.

Quality signals for maintainers. Open source maintainers find disclosure helpful β€” knowing AI was involved helps them assess how much scrutiny to give a PR and whether they are coaching a human contributor or reviewing AI-generated output.

Compliance. Some regulated industries require disclosure of AI tool usage. The European Union's AI Act includes transparency provisions around AI systems.

The Case for Disabling Attribution

Commit message standards. Strict commit conventions may not accommodate attribution lines, and the extra text can conflict with tooling that parses commit messages (Conventional Commits validators, changelog generators, semantic-release).

Tool vs. collaborator philosophy. Some developers view AI as a tool (like an IDE or linter), not a co-author. The human who directs, reviews, and approves the code is the true author.

Clean history. For some projects, keeping the commit history focused purely on code changes is a priority.

DCO sign-off policies. In projects that use git commit --signoff and the Developer Certificate of Origin, the Signed-off-by: line is a human's certification that they have the right to submit the change. Decide as a team whether an AI co-author trailer belongs next to it, and configure Claude Code accordingly.

How to Configure Attribution

Attribution is controlled by the attribution setting. Settings files live at:

  • User (all projects): ~/.claude/settings.json β€” on Windows, that is %USERPROFILE%\.claude\settings.json
  • Shared project: .claude/settings.json β€” commit it so the whole team gets the same behaviour
  • Personal, one project: .claude/settings.local.json β€” Claude Code adds it to .gitignore when it creates the file; if you create it by hand, add it yourself

To remove all attribution (commit trailer, PR line, and session link):

{
  "attribution": false
}

The false shorthand requires Claude Code v2.1.281 or later; older versions reject it and skip the whole settings file. If teammates may be on older versions, use the long form instead:

{
  "attribution": {
    "commit": "",
    "pr": ""
  }
}

To change the text rather than remove it, set your own string. This example keeps a commit trailer with your own wording and drops the PR line:

{
  "attribution": {
    "commit": "Co-Authored-By: AI assistant <ai@example.com>",
    "pr": ""
  }
}

What each key controls:

  • attribution.commit: the text (including any trailers) added to commit messages. Empty string hides it
  • attribution.pr: the line added to pull request descriptions. Empty string hides it
  • attribution.sessionUrl: whether cloud and Remote Control sessions append the claude.ai session link (true by default)

What about includeCoAuthoredBy? It is deprecated (since v2.0.62) in favour of attribution. Claude Code still honours "includeCoAuthoredBy": false in older settings files β€” it hides both the commit trailer and the PR line β€” but ignores it once you set attribution.commit or attribution.pr. There is no gitAttribution setting; if you copied one from an older guide, you can delete it.

Project-Level and Organisation-Level Control

Because attribution can be set in any settings file, different projects can behave differently β€” your open source contributions can keep attribution while your internal projects drop it. Commit .claude/settings.json so everyone who clones the repository gets the same behaviour.

Organisations that need a single policy can set attribution in managed settings, which individual developers can't override. Run /status inside Claude Code to see which settings files are active.

Using CLAUDE.md for Additional Control

You can also include Git commit instructions in your project's CLAUDE.md file (an AI coding config file):

## Git Commit Guidelines

When creating commits:
- Follow conventional commit format
- Keep the first line under 50 characters
- Do not include AI attribution in commit messages

This works more reliably than you might expect: Claude Code tells Claude that your own attribution instructions in CLAUDE.md or memory take precedence over the configured commit and PR lines β€” unless those lines are set in managed settings. If you need the rule enforced rather than requested, use the setting (or a commit-msg hook) instead of relying on CLAUDE.md alone.

How Other AI Coding Tools Handle Attribution

There is no industry standard for AI attribution in Git history, and defaults change between releases. Two tools document their behaviour clearly:

Tool Default behaviour How to change it
Claude Code Co-Authored-By: <model name> <noreply@anthropic.com> trailer on commits; Generated with Claude Code line on PRs attribution setting (false, or custom commit / pr strings)
Aider Adds a Co-authored-by trailer to commit messages (default since v0.85.0); the (aider) name suffix applies only when --attribute-author or --attribute-committer are set explicitly Aider's --attribute-co-authored-by, --attribute-author and --attribute-committer options; check aider --help for your version

Editor-based tools such as Cursor and GitHub Copilot take their own approaches, especially for their background or cloud agents β€” check each tool's current documentation before you standardise. If your team mixes tools (Cursor for editor work, Claude Code for terminal work, Aider for batch refactors), pick one convention and enforce it with a commit-msg hook so the history stays consistent regardless of which tool a developer used. For a broader feature comparison, see Claude Code vs Codex CLI vs Gemini CLI.

Control Deployments from Claude's Commit Messages

Because Claude writes your commit messages, it can also write the instructions your deployment tool reads from them. DeployHQ supports commit message deployment commands β€” square-bracket commands, anywhere in the message, case-insensitive β€” that change how an automatic deployment runs:

  • [skip_build] β€” deploy without running your build pipeline commands
  • [skip_cache] β€” run the build without reusing the previous build cache
  • [from_scratch] β€” deploy every file, not just the changes since the last deployment
  • [config_only] β€” deploy only your configuration files
  • [deploy: staging] β€” deploy to a named server or server group, even if it doesn't auto-deploy (the server must have the Commit command toggle enabled, so a commit message can never deploy somewhere you haven't allowed)

That lets you ask, in plain English, commit the copy fix and skip the build and get fix: correct pricing page typo [skip_build]. Add the commands to your CLAUDE.md so Claude knows when to use them:

## Deployment commands in commits
- Docs-only or copy-only changes: append [skip_build]
- After changing package-lock.json or composer.lock: append [skip_cache]
- Never add [deploy: ...] unless I explicitly ask for a deploy to a named server

One gotcha: don't put a deployment command in attribution.commit. That text is added to every commit Claude makes, so [deploy: production] there would trigger a production deploy on every push (for servers with the Commit command toggle on).

Ready to wire this up? Start a free DeployHQ trial and connect your repository β€” Claude's next push can be your first automated deployment.

Deploying Git Changes with DeployHQ

Once Claude Code has committed and pushed your changes, the next step is getting that code onto your servers. DeployHQ connects directly to your Git repository and deploys automatically β€” creating a seamless workflow from AI-assisted development to production.

The typical flow looks like this:

flowchart LR
    A[Claude Code commits & pushes] --> B[GitHub/GitLab receives push]
    B --> C[DeployHQ webhook triggers]
    C --> D[Build pipeline runs]
    D --> E[Code deployed to server]

When you deploy from GitHub (or deploy from GitLab) through DeployHQ, every push to your main branch can trigger an automatic deployment from Git. Combined with build pipeline integration for asset compilation, testing, and other pre-deployment steps, you get a complete CI/CD workflow without leaving your terminal. If you want Claude to trigger and monitor deployments directly, see how to deploy from your terminal with DeployHQ's agent tooling and our guide to driving DeployHQ from Claude Code, Cursor, and Windsurf.

If something goes wrong after deploy, one-click rollback restores the previous release without you having to revert commits on the main branch first β€” useful when Claude's PR turned out to have a subtle bug that only surfaced in production.

Claude Code handles the Git side (commits, branches, PRs), and DeployHQ handles the deployment side (builds, transfers, rollbacks). Together, they eliminate manual steps between writing code and shipping it.

Best Practices for Git Workflows with Claude Code

Review Claude's commits before pushing. Always inspect the commit messages and diffs Claude generates β€” you are ultimately responsible for the code that goes into your repository. Run /diff inside Claude Code to review the working tree, or git log --oneline -5 and git diff HEAD~1 before pushing.

Configure CLAUDE.md with your Git conventions. Specify your branch naming convention, commit message format, protected branches, and any project-specific rules. Claude reads this file at the start of every session.

Make smaller, focused commits. Smaller commits let Claude generate more precise commit messages and make your history easier to bisect when debugging.

Use descriptive branch names. Names that indicate the purpose of changes help Claude understand context when creating PRs or analysing branches.

Specify commit conventions explicitly. If you use Conventional Commits or another standard, tell Claude to follow it. This improves the readability and structure of your project history.

Leverage Claude for git archaeology. Use it to answer questions about past changes, understand why decisions were made, or find when bugs were introduced.

Use /compact in long sessions. In repos with extensive history or many files, /compact summarises the conversation so far to free up context without losing track of the task.

Protect main from direct pushes. Even with Claude reviewing diffs, route everything through a PR. Branch protection rules in GitHub/GitLab catch the case where Claude (or you) accidentally pushes to main instead of a feature branch. Pair this with an ask permission rule on git push so Claude always checks with you first.

Frequently Asked Questions

Does Claude Code need Git installed?

No β€” Git is optional for Claude Code itself, but you need it for every workflow in this guide (commits, branches, PRs, worktrees). On native Windows, Git for Windows is recommended because it provides Git Bash for Claude's Bash tool; without it, Claude Code uses PowerShell instead.

How do I disable the Co-Authored-By attribution?

Add "attribution": false to ~/.claude/settings.json (Claude Code v2.1.281+), or for older versions set "attribution": {"commit": "", "pr": ""}. For project-specific control, put the same setting in .claude/settings.json in your repo root. The older "includeCoAuthoredBy": false still works but is deprecated.

Can I customise what the attribution message says?

Yes. Set attribution.commit to any string β€” including your own trailers β€” and attribution.pr to the text you want in pull request descriptions. An empty string hides either one.

Why does my commit say Claude Sonnet 5 or Claude Opus instead of just Claude?

Current versions of Claude Code name the model that made the commit in the Co-Authored-By trailer. It falls back to plain Claude when it can't confirm the exact model version.

Can Claude Code commit and push to GitHub?

Yes. Claude commits locally with your Git identity and pushes with whatever credentials your git already uses. Pushing is a shell command, so it goes through Claude Code's permission prompts unless you have allowed it β€” add an ask rule for Bash(git push *) if you want a confirmation every time.

Can Claude Code resolve merge conflicts?

Yes. Claude reads both sides of a conflict, understands the intent behind each change, and proposes a resolution. You can guide it with preferences like keep our version of the timeout value or combine both implementations. It works for both merge and rebase conflicts.

Does Claude Code work with GitHub, GitLab, and Bitbucket?

Claude Code works with any Git hosting provider because it drives Git directly through the command line. For GitHub pull requests it uses the gh CLI; with GitLab or Bitbucket you can ask it to use those providers' CLIs in the same way. /install-github-app is github.com-only.

How does Claude Code handle large repositories?

Claude Code reads files on demand rather than loading the whole repository. Scope your prompts to specific directories or commit ranges, use /compact in long sessions, and consider worktrees with sparse checkouts (worktree.sparsePaths) for monorepos.

Can Claude Code create pull requests?

Yes. Ask Claude to create a PR for this branch and it will analyse the commit history, generate a descriptive title and body, and open the PR using the GitHub CLI. It can also update PR descriptions and summarise review feedback.

Does the Co-Authored-By line affect GitHub contribution graphs?

Adding a co-author doesn't remove anything from you: the commit's author is still you. GitHub only credits a co-author when the trailer's email is associated with a GitHub account.


Ready to automate your deployment workflow? Compare DeployHQ plans and connect your Git repository to deploy code to your servers automatically β€” every time you push.

For questions or support, reach out at support@deployhq.com or find us on Twitter/X @deployhq.