All articles

Safe Git Habits When Pairing with Claude

Letting Claude touch your repository is a big time-saver, but git is one place where a careless action is hard to walk back. A few habits keep the speed without the risk.

Commit in small, verifiable steps

The single best safety net is a tight commit history. When each commit does one thing, a mistake is easy to spot and easy to undo. Ask Claude to work the same way: make a change, verify it, commit, repeat. Small diffs are also easier to review, so problems surface before they compound.

Use permissions as guardrails

Permission rules decide what Claude can run without asking. Allow the everyday reads and let risky commands prompt you. You can be precise about which git commands are pre-approved.

{
  "permissions": {
    "allow": ["Bash(git status)", "Bash(git diff:*)", "Bash(git add:*)"],
    "deny": ["Bash(git push:*)", "Bash(git reset --hard:*)"]
  }
}

Keeping git push and destructive resets out of the allow list means those actions always pause for your say-so.

Block risky commands with a hook

For a stronger guard, a PreToolUse hook can inspect a command before it runs and refuse it. A hook that exits with code 2 blocks the action and feeds its reason back to Claude, so you can stop force-pushes to main no matter how a session got there.

Keep a human at the merge

Let Claude branch, commit, and open pull requests, but keep the merge to main as your decision. Review the diff yourself or with /review first.

Prefer reversible moves

Work on branches, not directly on main. Push to a feature branch. Avoid --force unless you truly mean it. With a clean history and branches to fall back on, almost anything Claude does can be undone.

Comments

Be the first to comment.