Kipt

Your prompts and skills, one keystroke away.

Explore

Claude Code and Git: commits, branches, pull requests and safe permissions

How Claude Code works with Git: commits and attribution, branches, pull requests with gh, worktrees, checkpoints vs Git, and permission rules for safe pushes.

By the Kipt team · Updated 26 October 2026

Claude Code works with Git by running ordinary git and gh commands for you: it reads your repo's status, writes commits, creates branches, and opens pull requests when you ask in plain language. You control how far it goes with permission rules, and you can isolate parallel work in git worktrees.

This guide covers the everyday Git workflow, how attribution works, where checkpoints fit next to Git, and which permission settings keep risky commands behind a prompt. All facts come from the official Claude Code docs.

How does Claude Code use Git?

Claude Code has no separate Git integration to install. It runs git through its Bash tool, the same way you would in a terminal. Two pieces of context help it do that well, according to the includeGitInstructions setting reference:

  • Built-in commit and PR instructions in the Bash tool's description, covering how to write commits and pull requests.
  • A git status snapshot read when a conversation starts, holding the current branch, the main branch, git status output and recent commits.

If you use your own Git workflow skills, set "includeGitInstructions": false to leave both out, or set CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1 for one session. Cloud sessions never include the snapshot.

Because Claude knows the recent history, you can point it at Git as a source. The best practices page suggests prompts like "look through ExecutionFactory's git history and summarize how its api came to be" instead of asking Claude to guess.

How do you commit with Claude Code?

Ask for it. "Commit these changes with a clear message" is enough; Claude reads the diff, writes the message and runs git commit. Before you commit, /diff shows the changes in your working tree, including Claude's edits and anything else uncommitted.

A good habit is to put your commit conventions in CLAUDE.md so every session follows them. The large codebases page uses an example rule: "Prefix commit subjects with the package name, for example api: add rate limiting."

What attribution does Claude Code add?

By default, commits get a Co-Authored-By: <name> <noreply@anthropic.com> trailer, where the name is the model that made the commit, and PR descriptions get a "Generated with Claude Code" line with a link. The attribution setting changes this:

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

Empty strings hide each part. In cloud and Remote Control sessions Claude Code also appends a claude.ai session link, which "sessionUrl": false removes. On v2.1.281 or later, "attribution": false hides all attribution in one line. Claude Code also tells Claude that your own instructions about attribution, such as a CLAUDE.md rule, take precedence over these lines, unless they are set in managed settings. The older includeCoAuthoredBy setting is deprecated.

How do you create pull requests?

The common workflows page shows the flow:

  1. "summarize the changes I've made to the authentication module"
  2. "create a pr"
  3. "enhance the PR description with more context about the security improvements"

On GitHub, install and sign in to the gh CLI. The best practices page says Claude knows how to use it for creating issues, opening pull requests and reading comments, and that without it Claude falls back to the GitHub API, where unauthenticated requests often hit rate limits. The old /pr-comments command was removed in v2.1.91; ask Claude directly to view PR comments instead.

When Claude creates a PR with gh pr create or glab mr create, Claude Code links the session to it. Later, claude --from-pr 1234 opens the session picker filtered to sessions linked to that PR.

Before you open a PR, two bundled commands help. /code-review checks the current diff for correctness bugs and can apply findings with --fix, and /security-review checks your branch against origin's default branch for vulnerabilities. For reviews that run on GitHub itself, see Claude Code Review and Claude Code GitHub Actions.

How do branches and worktrees fit in?

You can ask Claude to create a branch like any other Git command. For parallel work, Claude Code goes further with worktrees. claude --worktree feature-auth (or -w) creates a separate checkout under .claude/worktrees/feature-auth/ on a new branch named worktree-feature-auth, and starts Claude there. Run it again with another name in a second terminal and the two sessions cannot collide.

A few details from the worktrees docs and the common workflows page:

  • The repo needs at least one commit first, or the command fails.
  • New worktrees branch from the default branch on the remote. Set worktree.baseRef to "head" to branch from your current local work instead.
  • Add .claude/worktrees/ to .gitignore so worktree contents do not show up as untracked files.
  • On exit, a clean worktree from an unnamed session is removed automatically; one with changes or commits prompts you to keep or remove it.

Subagents can also run in their own worktree with isolation: worktree. The worktrees guide covers .worktreeinclude, cleanup and the desktop app's version.

Checkpoints vs Git: what is the difference?

Claude Code saves a checkpoint before each prompt that starts a turn. Run /rewind, or press Esc twice with an empty prompt, to restore code, conversation or both to an earlier point. That makes it cheap to let Claude try something and undo it.

Checkpoints are not version control, and the checkpointing docs say so directly: "Checkpoints are designed for quick, session-level recovery. For permanent version history and collaboration, continue using version control, such as Git, for commits, branches, and long-term history."

Checkpoints Git
Scope One Claude Code session Whole repository
Created Automatically before each prompt that starts a turn When you or Claude commit
Undoes files changed only by Bash No Yes, once committed
Undoes most subagent edits No Yes, once committed
Shared with your team No Yes, via a remote
Kept Last 100 per session; snapshots deleted about 30 days later by default Until you delete it

The table simplifies a few rows. Once Claude has edited a file with its own tools, /rewind also undoes later Bash changes to that file. A forked skill running in the foreground edits during your turn, so rewinding restores its edits; other subagents' edits to files Claude had not already touched stay. The 30-day retention follows cleanupPeriodDays, which you can raise.

A practical split: use /rewind for "that attempt was wrong, go back", and commit at each point you would want to return to tomorrow. The checkpoints guide has the full limitations list.

How do you keep Git safe with permissions?

Some Git commands are safe to run without asking, and some, like push or reset --hard, deserve a prompt. Permission rules in .claude/settings.json express that. This example from the permissions docs lets Claude commit freely and refuses pushes:

{
  "permissions": {
    "allow": [
      "Bash(npm run *)",
      "Bash(git commit *)"
    ],
    "deny": [
      "Bash(git push *)"
    ]
  }
}

Three rules of thumb from the same page:

  • Put the * after the subcommand. Bash(git log *) allows only git log, while Bash(git *) allows every git command. Claude Code warns about an allow rule like Bash(git * main).
  • Use ask rules for destructive commands. An ask rule such as Bash(git clean *) still prompts inside compound commands and subshells, even in auto mode.
  • Bash rules are not a security boundary. Bash(git push *) does not match git -C . push origin main. For enforcement that does not depend on command text, use sandboxing or a PreToolUse hook.

The .git directory is also a protected path: in default and acceptEdits modes Claude Code prompts before writing there, auto mode sends the write to its classifier, and only bypassPermissions (or plan mode with bypass permissions available) allows it without a check. See the permissions guide for modes and rule syntax.

A simple daily Git workflow

Putting it together:

  1. Start Claude in a worktree for each task: claude -w fix-login.
  2. Plan first for anything non-trivial, then let Claude edit.
  3. Use /rewind freely while iterating.
  4. Check /diff, run /code-review, then ask Claude to commit.
  5. Ask Claude to "create a pr", review the description, and push yourself if your rules deny pushes.

Teams often keep the commit and PR prompts they like as reusable text. Kipt stores prompts and Agent Skills as Markdown in a private GitHub repo you own, with {{name}} blanks for details such as a ticket number, and installs skills into Claude Code with one npx skills add command.

Questions

Can Claude Code make git commits?

Yes. Claude Code runs git through its Bash tool and has built-in instructions for writing commits and pull requests. By default each commit gets a Co-Authored-By trailer naming the Claude model, which you can change or remove with the attribution setting.

How does Claude Code create pull requests?

Ask it to "create a pr for my changes". On GitHub it works best with the gh CLI installed and signed in, and Claude Code links the session to the PR so claude --from-pr with the PR number finds it later.

How do I stop Claude Code from pushing to git?

Add Bash(git push *) to permissions.deny in your settings. The docs note that Bash rules match command text, so forms like git -C . push are not matched; use sandboxing or a PreToolUse hook if you need a hard boundary.

Are Claude Code checkpoints a replacement for git?

No. Checkpoints let you rewind Claude's file edits within a session with /rewind or Esc twice, but they do not track files changed only by Bash commands and are not permanent history. The docs say to keep using Git for commits, branches and long-term history.

How do I remove the Co-Authored-By line from Claude Code commits?

Set attribution.commit to an empty string in a settings file, or set attribution to false on v2.1.281 or later to hide both commit and PR attribution. Your own CLAUDE.md instructions about attribution also take precedence unless managed settings set the line.

More in Claude Code

All guides

Keep your prompts and skills in one place, in your own GitHub. Install every skill with one command.

Get started

Kipt is an independent product, not affiliated with or endorsed by Anthropic, OpenAI, Cursor or GitHub. Claude, ChatGPT, Codex, Cursor and GitHub are trademarks of their owners.