Git Workflows and Multi-File Edits
Git is the backbone of modern software development, and Claude Code integrates deeply with it. From creating commits with meaningful messages to managing branches, resolving merge conflicts, and opening pull requests, Claude Code handles git operations naturally. Combine that with its ability to make coordinated changes across dozens of files, and you have a tool that can handle even the most complex codebases.
In this lesson, you will learn how to use Claude Code for git operations and multi-file editing workflows.
What You Will Learn
- How Claude Code interacts with git
- Creating commits with descriptive messages
- Branch management and pull request workflows
- Resolving merge conflicts with Claude Code
- Multi-file editing techniques
- Large-scale refactoring across many files
- Best practices for reviewing multi-file changes
Git Basics with Claude Code
Creating Commits
The simplest git workflow is committing your changes:
Commit the current changes with a descriptive message.
Claude Code looks at the staged and unstaged changes, understands what was modified and why (from the conversation context), and creates a commit with a clear, conventional message. It often produces better commit messages than most developers write manually because it has full context of the changes.
You can also be more specific:
Stage all changes to the auth module and commit them.
The commit message should reference issue #42.
Viewing History and Changes
Claude Code can help you understand your git history:
Show me what changed in the last 5 commits.
What files did I modify today?
Show the diff between the main branch and this branch.
Branching
Create a new branch called feature/user-notifications
based on the main branch.
Switch to the develop branch and pull the latest changes.
Claude Code runs the appropriate git commands and handles any issues that come up, like stashing uncommitted changes before switching branches.
Pull Request Workflows
Claude Code can manage the entire pull request lifecycle.
Creating a Pull Request
Create a pull request for this branch.
Include a summary of all the changes we made.
Claude Code:
- Checks what branch you are on and what the target branch is
- Reviews all commits in the branch
- Writes a clear PR title and description summarizing the changes
- Creates the PR using the GitHub CLI (gh) or the GitHub MCP server
Reviewing Pull Requests
Review PR #123 and check for bugs, security issues,
and code style problems.
Claude Code reads the PR diff, analyzes the changes, and provides a thorough code review. It can also leave review comments directly on specific lines.
Updating a Pull Request
The PR reviewer asked us to add input validation
to the new endpoint. Make the changes and push.
Claude Code makes the requested changes, creates a new commit, and pushes to the branch.
Resolving Merge Conflicts
Merge conflicts are one of the most tedious aspects of git workflows. Claude Code handles them efficiently:
Merge the main branch into this feature branch
and resolve any conflicts.
Claude Code:
- Runs
git merge main - If conflicts occur, reads each conflicting file
- Understands the intent of both sides of each conflict
- Resolves the conflicts intelligently, keeping the correct behavior from both branches
- Stages the resolved files and completes the merge
For complex conflicts:
There are merge conflicts in src/services/auth.ts.
Our branch added password reset functionality.
Main branch changed the token validation logic.
We need both changes to work together.
By providing context about what each branch intended, you help Claude Code make better conflict resolution decisions.
Multi-File Editing
Coordinated Changes Across Files
Claude Code's ability to edit multiple files in a single operation is one of its most powerful features. Consider this request:
Add a new "archived" status to the project system.
This needs changes to:
- The database migration
- The Project TypeScript type
- The API endpoints that filter projects
- The frontend project list to show/hide archived projects
- The project settings page to add an archive button
Claude Code makes all these changes in a coordinated way, ensuring:
- The migration adds the correct column type
- The TypeScript type includes the new field
- API queries include the filter logic
- Frontend components handle the new status
- Everything compiles and type-checks
Pattern-Based Multi-File Edits
Sometimes you need to make the same type of change across many files:
Add error logging to every API route handler
in src/routes/. Use the existing logger utility
from src/utils/logger.ts.
Claude Code reads each route file, understands the error handling pattern, and adds consistent logging across all of them.
Add the "data-testid" attribute to every button
in the src/components/ directory. Use the pattern
data-testid="btn-\{component-name\}-\{action\}".
Rename Across the Codebase
Rename the "user" module to "account" throughout
the entire codebase. This includes:
- Renaming files and directories
- Updating all imports
- Updating route paths
- Updating database table references
- Updating test files
Claude Code handles all of this in one coordinated operation, ensuring nothing breaks.
Large-Scale Refactoring
For major refactoring that touches dozens or hundreds of files:
Planning Phase
I want to migrate all our API endpoints from Express
to Fastify. Before making any changes, give me a plan:
- How many files need to change?
- What are the key differences we need to handle?
- What order should we migrate in?
- What risks should we watch for?
Claude Code analyzes your codebase and produces a migration plan.
Staged Execution
Execute the plan in stages:
Start with Stage 1: Migrate the utility middleware
that does not depend on Express-specific APIs.
After reviewing and testing:
Stage 1 looks good and tests pass. Move to Stage 2:
Migrate the auth routes.
Verification
After each stage, Claude Code can verify the changes:
Run the full test suite and type checker.
Show me any failures related to the migration.
Best Practices for Git Workflows
Let Claude Code write commit messages. It has full context of what changed and why, so its commit messages are often more descriptive than manually written ones.
Review diffs before pushing. Even though Claude Code is careful, always review the git diff before pushing:
Show me the full diff of what we are about to push.
Use branches for significant changes. Ask Claude Code to create a branch before starting any large feature or refactoring:
Create a branch for this work before we start making changes.
Commit frequently. Ask Claude Code to commit after each logical unit of work rather than accumulating many changes:
Commit what we have so far. We will continue in the next step.
Use conventional commits. If your team uses conventional commit messages, mention it in your CLAUDE.md:
## Git Conventions
Use conventional commits: feat:, fix:, refactor:, test:, docs:, chore:
Best Practices for Multi-File Edits
Start with a plan. For any change touching more than 5 files, ask Claude Code to plan before executing.
Verify after each stage. Run tests and type checks between stages of a large refactoring.
Review incrementally. Do not wait until all changes are done to review. Review each batch of related changes.
Keep your test suite healthy. Multi-file edits are only safe when you have tests to verify nothing broke.
Key Takeaways
- Claude Code integrates deeply with git, handling commits, branches, merge conflicts, and pull requests through natural language
- Claude Code writes descriptive commit messages based on full context of the changes and conversation
- For merge conflicts, provide context about what each branch intended to help Claude Code resolve conflicts correctly
- Multi-file editing is one of Claude Code's strongest capabilities, enabling coordinated changes across database, API, types, and frontend
- For large-scale refactoring, break the work into planned stages with verification between each stage
- Always review diffs before pushing, commit frequently in logical units, and use branches for significant changes
- Pattern-based multi-file edits let you apply consistent changes (like adding logging or test IDs) across many files at once

