Claude Code with Git and GitHub
Git is your safety net. With it, every change Claude Code makes can be reviewed and undone. A few habits make the workflow smooth.
One branch per task#
Make a branch before you start. If the result is not right, you throw the branch away and your main code is untouched.
git switch -c add-dark-mode
claudeReview before you commit#
Read the diff yourself. Claude's changes are proposals until you accept them.
git diff
git statusLet Claude write the commit#
Ask for a commit message that explains why the change was made, not only what changed:
commit these changes with a clear message that explains whyPull requests with the GitHub CLI#
If you have the GitHub CLI (gh) installed and signed in, Claude can open a pull request for you:
push this branch and open a pull request with a short summary and a test planCheck the title and description before you ask anyone to review it.
Block the risky commands#
Add deny rules so Claude can never force-push or rewrite shared history:
{
"permissions": {
"deny": [
"Bash(git push --force:*)",
"Bash(git reset --hard:*)"
]
}
}Run several tasks at once#
Use git worktree to check out another branch in a second folder, then run a separate Claude Code session in each. The sessions cannot overwrite each other.