Claude Code Git

Claude Code git tasks start with a plain request, such as "create a pr for my changes." Claude already knows your branch and your recent commits. It reads a snapshot of your repo when each conversation starts. This guide shows how to commit, open a pull request, work on two branches at once and control the co-author line.

What Does Claude See In My Repo?

At the start of each conversation, Claude Code reads a git status snapshot. It holds the current branch, the main branch, the `git status` output and your recent commits. Claude also gets built-in steps for how to write commits and pull requests.

You can turn both off. Set `includeGitInstructions` to `false` in your settings. The docs suggest this when you use your own git workflow skills.

How Do I Make A Commit?

Ask for one in plain words. Claude follows its built-in steps for writing commits.

Each commit gets a `Co-Authored-By` trailer by default. Pull request descriptions get a line of plain text instead. The next section shows how to change both.

How Do I Change Or Remove The Co-Author Line?

Use the `attribution` setting. To hide all of it, set `attribution` to `false`, which needs Claude Code v2.1.281 or later.

To change the text, set its parts one by one. This example from the docs swaps the commit line, removes the pull request line and drops the session link:

{
  "attribution": {
    "commit": "Generated with AI\n\nCo-Authored-By: AI <ai@example.com>",
    "pr": "",
    "sessionUrl": false
  }
}

The old `includeCoAuthoredBy` setting has been deprecated since v2.0.62. A rule about attribution in your CLAUDE.md also wins over these lines. The one exception is a line set in managed settings.

How Do I Open A Pull Request?

Ask Claude directly, with words like "create a pr for my changes." You can also go step by step. First, ask Claude to sum up your changes, and then type `create a pr`. Last, ask it to add more context to the description. Claude can also work on pull requests in GitHub when someone tags @claude in a comment.

Read the pull request before you submit it. Ask Claude to point out any risks it sees. If you want a second set of eyes, compare the review plugins here.

When Claude opens the pull request with `gh pr create` or `glab mr create`, it links your session to it. To find that session later, run this with your own PR number:

claude --from-pr 1234

It also takes a GitHub PR link, a GitLab merge request link or a Bitbucket pull request link.

How Do I Work On Two Branches At Once?

Use a worktree. A git worktree is a separate folder with its own files and its own branch. It shares the same history and remote as your main checkout. Your repo needs at least one commit first.

claude --worktree feature-auth

This puts the worktree in `.claude/worktrees/feature-auth/` at the root of your repo. It also makes a new branch named `worktree-feature-auth`. Run the same command with a different name in a second terminal, and you have two sessions that never touch each other's files. If you leave out the name, Claude picks one, such as `bright-running-fox`.

Two setup steps save you trouble:

1. Add `.claude/worktrees/` to your `.gitignore`. Then the worktree files won't show up as untracked in your main checkout. 2. Set up your tools inside the worktree. It is a fresh checkout, so you may need to ask Claude to install your dependencies there.

Can I Start A Worktree From A Pull Request?

You can. Put the number after a `#`, and wrap it in quotes so your shell doesn't treat it as a comment:

claude --worktree "#1234"

Claude Code fetches that pull request from `origin` and puts the worktree in `.claude/worktrees/pr-1234`.

Which Branch Does A New Worktree Start From?

It starts from the default branch on your remote, which is usually `main`. To start from your current work instead, add this to your settings:

{
  "worktree": {
    "baseRef": "head"
  }
}

What Happens To A Worktree When I Exit?

It depends on what is in it. If the worktree is clean and the session has no name, Claude removes the worktree and its branch for you. If it has work in it, Claude asks whether to keep it or remove it.

Runs with `-p` have no exit prompt, so they leave their worktrees behind. To remove one, run `git worktree remove`.

Can Claude Read My Git History?

It can. Pipe your log into a one-off run:

git log --oneline -20 | claude -p "summarize these recent commits"

Which Plugins Help With Git?

These plugins add commands and tools for git work:

FAQ

Does Claude Add Itself As A Co-Author?

It does by default, so each commit gets a `Co-Authored-By` trailer. Set `attribution` to `false` to hide it.

Do Worktrees Work Without Git?

They need a git repo. For other version control tools, the docs say to set up hooks that replace the git steps.

How Do I Find The Session That Made A Pull Request?

Run the command from the pull request section above, with your PR number or link. It opens the session picker and shows only the sessions linked to that pull request.

Can I Write My Own Commit Rules?

You can. Put them in your CLAUDE.md, since a rule there wins over the default attribution lines. If you use your own git skills, set `includeGitInstructions` to `false` so the built-in steps stay out of the way.

Ad Sponsor this spot. Reach developers who pick skills