Claude Code and git: commits, pushes, PRs and attribution
What Claude Code does with git: when it asks before a commit or push, rules that allow git diff but ask on git push, the Co-Authored-By trailer, and PRs with gh.
Claude Code runs git itself, through its Bash tool, and starts each conversation with a snapshot of your branch, git status and recent commits. Whether it asks before a commit or a push depends on the permission mode: in Manual mode only read-only git runs unasked, while auto mode, the starting mode for terminal sessions since v2.1.283, lets it push to any branch of your repository, default branch included, and blocks force pushes. To be asked before a push, add "ask": ["Bash(git push *)"] to .claude/settings.json; it matches git push as written, not every way of pushing, and /ship does not consult it. Commits carry a Co-Authored-By trailer naming the model; the attribution setting changes or removes it (includeCoAuthoredBy is deprecated). Pull requests go through gh, so install it and run gh auth login.
What Claude Code does with git by default
There is no separate git integration to switch on. Claude runs the same git and gh commands you would, in your shell, with your credentials. Anthropic’s quickstart puts it as “Claude Code makes Git operations conversational”, with prompts such as these:
what files have I changed?
commit my changes with a descriptive message
create a new branch called feature/quickstart
show me the last 5 commits
help me resolve merge conflictsCopiedTwo pieces of git context arrive without you asking, per the includeGitInstructions entry: built-in instructions for writing commits and pull requests, and a snapshot of the current branch, the main branch, git status output and recent commits, read when the conversation starts. Cloud sessions never get the snapshot, and a -p run started with --system-prompt or a custom --agent loses it too.
If you use your own commit skill or conventions and want the built-in ones gone, turn both off:
{
"includeGitInstructions": false
}Copiedor, for one session, CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 claude, which takes precedence over the setting.
Does it ask before committing or pushing?
Anthropic’s overview says Claude makes the edits, runs the tests “and commits the changes if you ask.” Whether you are then asked to approve the git commit and the git push is the permission mode’s call, as of November 2026:
| Mode | Read-only git, such as git status | git commit | git push |
|---|---|---|---|
Manual | Runs unasked (“read-only forms of git”) | Prompts | Prompts |
Auto (the default for terminal and VS Code since v2.1.283) | Runs unasked | The classifier decides; amending a commit this session did not make is blocked | Allowed to any branch of the repository you are in, default branch included; force push blocked |
The auto mode column is from the permission modes page. Its classifier also blocks git reset --hard, git checkout -- ., git restore ., git clean -fd and dropping or clearing stashes, which would discard uncommitted work, and pointing a remote somewhere new with git remote set-url or git remote add unless you named that remote. A push to a branch whose name marks it as a deploy target, such as production or gh-pages, is judged on its own. Telling Claude “don’t push until I’ve reviewed” works there: the classifier treats it as a block for the actions it reviews. It is still a model reading the transcript, and the sentence can be lost when the conversation is compacted, so a push that must wait belongs in a rule. In Manual mode the prompt already stops the push.
Choosing “Yes, and don’t ask again” on a git prompt saves an allow rule for that command, per repository, in .claude/settings.local.json, which Claude Code adds to your global git excludes so it stays out of commits. What each mode still stops when nobody is watching is the subject of running Claude Code without permission prompts.
Rules that allow git status and diff but ask before a push
A rule fixes the behaviour whatever the mode, and an ask rule that names a command still prompts in auto mode. This shared project file lets the everyday read commands and local commits run, and asks before a push, a new PR or a merge written in the usual form:
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"permissions": {
"allow": [
"Bash(git status *)",
"Bash(git diff *)",
"Bash(git log *)",
"Bash(git add *)",
"Bash(git commit *)"
],
"ask": [
"Bash(git push *)",
"Bash(gh pr create *)",
"Bash(gh pr merge *)"
]
}
}CopiedSave it as .claude/settings.json in the repository and commit it for the whole team, or put it in ~/.claude/settings.json for every project of yours. In the committed file the ask rules apply at once, while the allow rules wait until each person accepts the folder’s trust dialog. Lists merge across files, and the permissions page is exact about how the rules meet:
- “Rules are evaluated in order: deny, then ask, then allow.” An ask or deny from any file beats an allow from any other, so a
Bash(git *)allow does not undo the push prompt. - A trailing
*after a space also matches the bare command:Bash(git push *)coversgit pushwith no arguments as well asgit push --force origin main. Put the*after the subcommand;Bash(git *)is every git command. - A compound command runs unasked only if every part is allowed, and a deny or ask applies if any part matches, so
git add . && git pushstill prompts. - The match is on the command as written.
git -C . pushandgit -c push.default=current pushdo not matchBash(git push *), and the docs say plainly that such a rule “isn’t a security boundary around the program.” Your other rules and the mode decide those forms: Manual mode prompts for them, auto mode’s classifier judges them, and aBash(git *)allow lets them run unasked. For a hard stop, limit the credential (below).
To refuse pushes outright rather than ask, move Bash(git push *) to deny. Two related prompts come from Claude Code itself: a cd into a different directory followed by git prompts, because git there can run that directory’s hooks, and in acceptEdits mode a write inside .git, .gitconfig or .gitmodules prompts. On native Windows, where Claude can use PowerShell instead of Bash, the same rules are written PowerShell(git push *); the Windows guide covers why a Bash deny rule there can switch PowerShell off. For where each settings file lives and which one wins, see Claude Code’s settings.json.
The Co-Authored-By trailer and how to change it
By default every commit Claude makes ends with a trailer like this, naming the model that made the commit (a subagent’s model if a subagent committed):
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>CopiedWhen Claude Code cannot confirm the exact model version it writes Claude, and for a model it does not recognise, such as one behind a custom ANTHROPIC_BASE_URL, it writes Claude Code. Pull request descriptions get a plain line instead: 🤖 Generated with [Claude Code](https://claude.com/claude-code). Cloud and Remote Control sessions also add a link to the claude.ai session, as a Claude-Session trailer on commits and a URL in the PR.
The setting is attribution, which replaced includeCoAuthoredBy in v2.0.62. The old key is still read, but is ignored once attribution.commit or attribution.pr is set. To remove all of it, on v2.1.281 or later:
{
"attribution": false
}CopiedAn older Claude Code rejects false and skips the whole settings file that holds it, so in a file older versions also read, such as a team’s committed one, use the long form:
{
"attribution": {
"commit": "",
"pr": "",
"sessionUrl": false
}
}Copiedcommit also takes your own text, trailers included, with \n for line breaks. Claude Code tells Claude that an instruction about attribution in your CLAUDE.md or memory takes precedence over these lines unless they come from managed settings, so a team can also settle it there.
Commits and pull requests with gh
Claude opens pull requests with the GitHub CLI. In Anthropic’s best practices: “With gh installed and signed in, for example, Claude will open pull requests and read review comments without any explanation from you.” So the setup is gh on the PATH and one gh auth login, then a prompt:
create a pr for my changesCopiedWhen Claude creates the PR with gh pr create (or glab mr create on GitLab) Claude Code links the session to it. Later, claude --from-pr 1234 opens the session picker filtered to sessions on that PR. While a branch has an open PR, the footer shows a clickable badge such as PR #446, green when approved, yellow pending review, red for changes requested and gray for a draft; it needs a GitHub token, from GH_TOKEN, GITHUB_TOKEN or gh auth login; with no token and no gh installed, the footer says install gh for PR status.
Three built-in commands carry the rest of the loop. /diff shows the working-tree changes, including Claude’s. /code-review reviews the current diff or a PR you name; the Claude Code review guide covers it. /ship (Claude Code v2.1.330 or later, with gh 2.63 or later and git 2.38 or later, in a terminal on your own clone) goes further: it can commit all your uncommitted changes, new files included, push the branch and open the PR as you, then review it and keep pushing fixes for failing checks and comments. Note what it does without asking:
- “
/shipproceeds with no confirmation prompt.” A line endingEsc to cancelappears before the commit and before the push, and it carries on after a few seconds. A commit it made stays if you cancel before the push;git reset HEAD~1undoes it and keeps your files. - An ask rule on
Bash(git push *)is not consulted for/ship’s own commit and push, and auto mode’s check does not run for them either. During the watch that follows, Claude’s pushes are written asgit -c core.hooksPath=/dev/null push, which that rule does not match, so it adds no prompt there; an ask rule onBash(git *)does. A deny rule onBash(git push *)is respected:/shipleaves the commit and push to you, and no watch starts. - Run
git statusfirst./shiplooks for secrets by file name, such as.env, so look inside the files yourself, and aReaddeny rule does not keep a file out of the commit. - On the default branch it commits on a new branch. While it watches the PR and acts without a message from you, Claude Code blocks it from merging, approving, turning on auto-merge or force-pushing, and leaves the merge to you. Those limits are off while Claude answers a message you type, and if auto-merge is on for the PR, GitHub still merges once the checks and reviews allow, and a fix Claude pushes can bring that about.
For Claude answering @claude on PRs and issues from CI instead of your machine, see Claude Code GitHub Actions.
Checkpoints, rewind and git
/rewind, or Esc twice on an empty prompt, restores code, conversation or both to an earlier prompt. Anthropic’s checkpointing page is clear that this is not git: checkpoints track “all changes made by its file editing tools”, a file that only a Bash command changed is not tracked, and the section on version control is headed “Not a replacement for version control.” The docs describe a restore only in terms of files, so undo a commit with git (git reset HEAD~1 keeps the changes in your files), and count a push as beyond any checkpoint, like the other actions on remote systems the overview says “can’t be checkpointed.” A commit or a branch of your own before a large change gives you a point git can return to.
Worktrees and credentials
To run several sessions on one repository without their edits colliding, claude --worktree feature-auth starts one in its own git worktree (the repository needs at least one commit); Claude Code worktrees covers where they go, .worktreeinclude and cleanup.
What Claude can push to is whatever your git and gh credentials can reach, since it uses them as you. On a server, that makes the credential the real boundary: a deploy key or a token scoped to the repositories the agent needs holds where a permission rule matched on command text does not. GitHub access for a coding agent on a server sets up each option and explains its errors.