HomeClaude Code CLIGit Workflow with Claude Code
intermediate15 min read· Module 4, Lesson 8

🔀Git Workflow with Claude Code

Master git operations through your AI coding assistant — branches, commits, PRs, and more

Git Workflow with Claude Code

Claude Code doesn't just write code — it can manage your entire Git workflow. From creating branches to opening pull requests, you can do everything through conversation.

Basic Operations

Checking Repository Status

> What's the current git status? > Show me uncommitted changes > What branches are available?

Claude Code will run git status, git diff, and summarize the results.

Creating a New Branch

> Create a new branch called feature/add-user-auth > Switch to a new branch for fixing the login bug

Staging and Committing

> Add all changes and commit with a good message > Only commit the modified TypeScript files > Commit changes with the message "fix authentication error"

Claude Code automatically writes clear, descriptive commit messages based on actual changes.

Creating Pull Requests

This is one of Claude Code's most powerful features:

> Create a PR for this branch > Push changes and create a pull request with a detailed description

Claude Code will:

  1. Analyze all commits in the branch
  2. Write a detailed PR title and description
  3. Push the branch to remote
  4. Open the PR via gh CLI

Resolving Merge Conflicts

> There's a merge conflict in auth.ts — resolve it > Merge main into my current branch and resolve any conflicts

Claude Code understands both sides of the conflict and chooses the right resolution based on context.

Rebasing

> Rebase my branch on main > Squash the last 3 commits into one

Reviewing Changes

> Show me a summary of all changes on this branch compared to main > What files changed since the last commit? > Review the changes in database.ts

Advanced Git Commands

> Show me the commit log for the past week > Who last changed this file? (git blame) > Search the log for a commit about performance fixes > Stash the current changes

Complete Workflow — From Idea to PR

Here's a typical workflow:

# 1. Start a new feature > Create a new branch feature/user-profile # 2. Write the code > Create a UserProfile component with name, email, and avatar display # 3. Review changes > Show me what changed # 4. Commit changes > Commit changes with a descriptive message # 5. Make additional tweaks > Add error handling to the component # 6. Commit again > Commit the new changes # 7. Create PR > Push and create a PR with a detailed description

Handling Merge Conflicts Step by Step

When Claude Code encounters a merge conflict, it:

  1. Reads both versions — understands what changed on each branch
  2. Analyzes intent — determines what each change was trying to achieve
  3. Proposes resolution — suggests the best merge that preserves both intents
  4. Applies the fix — edits the file and marks the conflict as resolved
> Merge main into my branch Claude Code: I found conflicts in 2 files: - src/auth.ts (lines 45-62) - src/config.ts (line 12) For auth.ts, main added rate limiting while your branch added OAuth support. I'll keep both changes since they don't overlap functionally. For config.ts, both branches changed the timeout value. Main set it to 30s, your branch set it to 60s. Which do you prefer?

Best Practices

  1. Small, frequent commits — Ask Claude Code to commit after each logical change
  2. Descriptive commit messages — Claude Code writes excellent ones automatically
  3. Review before committing — Ask Claude Code to show diffs first
  4. Separate branches for each feature — Keep an organized workflow
  5. Never push to main directly — Always use pull requests
  6. Use conventional commits — Claude Code can follow formats like feat:, fix:, docs:

Handling Common Mistakes

Can't push:

> Push failed — what's wrong? Claude Code: The remote branch is ahead. I'll fetch updates and merge...

Forgot to create a branch:

> I committed on main by mistake — move the commit to a new branch

Undoing a commit:

> Undo the last commit but keep the changes

Recovering deleted work:

> I accidentally deleted a file — can you recover it from git history?

Git Configuration Tips

You can ask Claude Code to help with Git config:

> Set up my git config with my name and email > Add a .gitignore for a Node.js project > Show me the current git configuration

Summary

Claude Code makes Git intuitive by:

  • Converting your natural language requests into correct Git commands
  • Automatically writing clear commit messages
  • Creating detailed pull requests
  • Intelligently resolving merge conflicts
  • Handling any Git operation you can imagine

Next: We'll learn how to use Claude Code for effective debugging.