Commit, push and open a pull request with Claude Code
How to have Claude Code write commit messages, push a branch and open a PR with gh: prompts that work, permission rules, attribution settings and checks.
Claude Code can commit, push and open a pull request when you ask in plain language: "commit these changes", "create a pr". It runs ordinary git and gh commands through its shell tool, so the result is exactly what you would have typed yourself. What matters is the setup around it: a branch, a reviewed diff, permission rules you trust, and a message convention it can follow.
#How do you commit with Claude Code?
Ask for it in the session that made the changes:
Commit what we changed for the login fix. One commit, conventional commit
style, and explain why in the body, not just what.
Claude looks at git status and git diff, stages the files, writes the message from the changes and from the conversation (which is why it usually knows the "why"), and runs git commit. Each of those is a Bash call, so in the default permission mode you approve them or have allow rules for them.
Habits that pay off:
- Review before you commit. Run
/diffto see the working tree, including everything Claude edited so far, or read it in your editor. A commit is the cheapest undo point you have; see how to undo what Claude Code changed. - Commit in small units. Ask for a commit after each working step, not one at the end of a three-hour session.
- Put the convention in CLAUDE.md. "Commit messages: imperative mood, under 72 characters, no emoji. Never use
--no-verify." Claude follows it, and your git hooks (lint, tests) still run. More in writing a CLAUDE.md. - Stage on purpose. If your tree has unrelated changes, say "only commit the files under
src/auth/".
#How do you push a branch safely?
Work on a branch, not on main. Ask Claude to create one before it starts:
Create a branch fix/login-redirect, then fix the redirect bug.
Then "push this branch" runs git push -u origin fix/login-redirect. Two rules worth writing into CLAUDE.md: never push to main, never force-push. Better still, enforce it where Claude cannot talk its way around it: branch protection on the remote. Claude Code's own background sessions follow the same rule; the agent view docs say they never push to main or master, force-push or merge.
#How do you open a pull request?
Claude uses the GitHub CLI, gh. Install it and run gh auth login once; for GitLab the equivalent is glab. Then:
create a pr
Claude runs gh pr create with a title and a description it writes from the branch's commits and diff. The official guidance is to treat it as a first draft: ask for more ("add the security implications to the description", "list the risks and what I should test") and read it before you submit.
Claude Code links the session to the PR when Claude creates it with gh pr create or glab mr create. That is useful later:
claude --from-pr 1234
opens the session picker filtered to sessions linked to that PR, so you can return to the conversation when review comments arrive. Pasting the PR URL into the /resume picker's search works too.
#Which permission rules make this less tedious?
By default Claude asks before each Bash command except a built-in set of read-only ones. Allow the harmless git reads, and keep the writes behind a prompt. In .claude/settings.json (shared) or .claude/settings.local.json (just you):
{
"permissions": {
"allow": [
"Bash(git status)",
"Bash(git diff *)",
"Bash(git log *)"
]
}
}
Rules are Bash(<command pattern>), and * matches the rest of a command. Many people also allow git commit * once they trust their review habit, and leave git push * and gh pr create * as prompts, so nothing leaves the machine without a yes from them. Pick the line that matches your risk. The permission modes article explains acceptEdits, plan and the rest.
#How do you change or remove the attribution line?
Claude Code adds attribution to the commits and pull requests it creates. The attribution setting has two keys, commit and pr, to change or hide each; the older includeCoAuthoredBy is deprecated in favor of it. A separate setting, includeGitInstructions, removes the built-in commit and PR instructions from Claude's context entirely, which you would only do if you supply your own. Look the exact shape up in the settings reference for your version; it is a setting your team should decide on once, in the shared .claude/settings.json.
#What should you check before merging?
A PR written with an assistant needs the same review as any other, and a bit more suspicion about tests that were edited to pass. A short checklist:
- Read the diff, not the description.
- Run the tests and the build yourself, or via CI.
- Look at what changed in test files and config files in particular.
- Ask Claude for its own review with
/code-reviewbefore you request one from a human; see using Claude Code to review code. - Check that no secrets or
.envfiles were staged.
#Can you make this repeatable?
Yes: write the workflow once as a slash command or skill. A /ship command in .claude/commands/ship.md can say "run the tests, fix failures, commit with a conventional message, push the branch, open a PR, and print the URL". See slash commands. For unattended work, headless mode runs the same steps from a script or CI.
#In Relais
Relais has a Changes tab like a source-control panel: each repository of the project with its branch, its changed files, and the commits to pull and push. A dot marks the files the current session changed. "Commit" and "Commit & push" ask Claude in the conversation to write the messages and commit, only for the session's own files, so two sessions in one repository do not commit each other's work. The session turns green once its changes are pushed. Pull and push happen right away. Relais does not open pull requests for you; in the same session you can ask Claude to, as in a terminal. See features.