How to Use Claude Code with Git (Without Losing Work)

Duncan RogoffDuncan Rogoff July 24, 2026 7 min read
A railway junction where a single track splits into several diverging and rejoining lines, representing Git branches and merges
Original image, Claude Code Club

How to Use Claude Code with Git: The Short Answer

Claude Code edits real files on your machine, which means a single task can change dozens of lines across your project. Git is what makes that safe. Before you ask Claude to do anything, you commit - that saves a clean snapshot you can always return to. You let Claude make its changes, then you look at the diff, which is Git showing you exactly what moved. If the change is good, you keep it. If it is not, one command puts everything back the way it was. That loop - commit, change, review - is the whole habit, and once it is muscle memory you can let Claude work fast without ever risking work you cannot recover.

Commit Before You Let Claude Touch Anything

The single most important habit is to start from a clean commit. Before you hand Claude a task, make sure everything you care about is committed - run git status and confirm there is nothing uncommitted you would hate to lose. Now, whatever Claude does next, you have a marked point in time to come back to. If a task goes sideways, git restore or git checkout on the changed files wipes the mess and drops you right back on solid ground. Builders who skip this are the ones who message me having lost an afternoon of work to a change they accepted too fast.

Work on a Branch, Not on Main

For anything bigger than a one-line fix, put Claude on its own branch. A branch is a private copy of your project where Claude can rewrite as much as it needs while the version that works sits untouched on main. If the experiment pays off, you merge it in. If it does not, you delete the branch and it is as if it never happened. This is how you let Claude attempt something ambitious - a refactor, a new feature - without betting your working code on it.

  • Create a branch before the task: git checkout -b claude-feature-x. Now every change lands there, not on main.
  • Let Claude work as freely as it wants on that branch - the safety net is that main is still clean.
  • Merge only after you have reviewed and tested. If it went wrong, git checkout main and delete the branch.

The Checkpoint Habit

I call the whole routine the Checkpoint Habit, and it is three moves you repeat on every task: checkpoint, change, check. Checkpoint means commit before you start. Change means let Claude do the work. Check means read the diff before you accept and commit again. Each completed task becomes its own checkpoint, so your project history turns into a row of save points. When something breaks two hours later, you are never asking where did this go wrong - you can walk back one checkpoint at a time until you find the exact commit that introduced it.

The Checkpoint Habit, one loop per task

MoveCommandWhy it protects you
Checkpointgit add -A && git commitA clean save point exists before any change
ChangeClaude edits the filesWork happens against a known-good baseline
Checkgit diff, then commit or restoreNothing is kept until you have seen it

Always Read the Diff Before You Accept

The diff is where you stay in control. When Claude finishes a task, git diff shows you every line it added or removed. Read it. You are not looking to understand every character - you are looking for anything you did not ask for: a config file that changed, a dependency that appeared, a chunk of code deleted that you wanted kept. Ninety percent of the time the diff is exactly what you expected and you commit it. The other ten percent is precisely why you look. Accepting changes without reading the diff is how surprises end up in production.

Join the Club

The Checkpoint Habit is one of the working routines we teach inside Claude Code Club - the community where builders learn to move fast with Claude Code without the messes that come from moving carelessly. Inside you get the workflows, the guardrails, and the room to ask when a change goes sideways. If you want to build with Claude Code and keep your work safe while you do it, that is exactly what the Club is for.

Free Claude Code drops, straight to your inbox

Short, practical drops on skills, MCP, agents, prompts, and more. No spam, unsubscribe anytime.

Frequently asked questions

Do I need to know Git to use Claude Code?

You only need three commands to be safe: commit to save a checkpoint, diff to review what changed, and restore or checkout to undo. Claude can even run these for you if you ask, but knowing what they do keeps you in control of your own work.

How do I undo a change Claude Code made?

If you have not committed it yet, git restore on the changed files (or git checkout .) reverts them to your last commit. If you committed on a branch, delete the branch. This is why committing before each task matters - it gives you a clean point to return to.

Should Claude Code work on main or a branch?

For a tiny fix, main is fine as long as you committed first. For anything larger - a refactor or a new feature - put Claude on its own branch so the working version stays untouched and you can throw the experiment away if it does not pan out.

Why review the diff if Claude Code usually gets it right?

Because the times it does not are the expensive ones. The diff takes seconds to read and catches the unexpected change - a deleted line, a new dependency, an edited config - before it reaches your repo. It is the cheapest insurance in your workflow.

Last reviewed by Duncan Rogoff on July 24, 2026

Duncan Rogoff

Written by

Duncan Rogoff

Apple · PlayStation · Charles Schwab

Keep reading

Claude CodeDatabases

How to Connect Claude Code to a Database (Safely)

The safe way to connect Claude Code to a database is through a read-only MCP server, not by pasting rows into a prompt. Here is the exact setup I use - a least-privilege database user, an MCP bridge, and a few hard rules - so Claude can read your schema and answer questions about your data without ever being able to break it.

David Iya 8 min
Read article

Ready to build it yourself?

Join Claude Code Club, the #1 community for learning claude code, for $9/month.

← Back to the blog