Git Integration
Claude Code integrates deeply with Git, helping you manage version control workflows. From creating commits to managing branches, Claude can automate many Git operations while following best practices.
Git Workflow Basics
Viewing Status
Claude can help you understand the current Git state:
Check git status, tell me what changes there areClaude will run git status and explain the results, including:
- Modified files
- Staged changes
- Untracked files
- Current branch information
Viewing Diffs
Show me my changes to src/auth/login.tsClaude will run git diff and explain what changed and its impact.
Creating Commits
Smart Commit Messages
Claude can analyze your changes and generate meaningful commit messages:
Create a commit for the current changesClaude will:
- Check all changed files
- Analyze the nature of changes
- Generate a message following Conventional Commits specification
- Create the commit
Example commit message:
feat(auth): add JWT refresh token support
- Implement token refresh endpoint
- Add refresh token to user session
- Update authentication middlewareFollowing Commit Conventions
Claude understands common commit message conventions:
- Conventional Commits
- Angular Commit Guidelines
- Semantic Commit Messages
You can specify the convention your project uses:
Create a commit using the Angular commit conventionPhased Commits
For work containing multiple logical changes, create separate commits:
Create a commit for the authentication changes,
and another commit for the UI changesClaude will:
- Identify different types of changes
- Stage related files separately
- Create independent commits for each group
Branch Management
Creating Branches
Create a new branch feature/user-profileClaude will:
- Check current branch status
- Create the new branch
- Switch to the new branch
- Confirm the operation succeeded
Branch Naming Conventions
Claude can help follow branch naming conventions:
Create a branch for adding email notification featureClaude will suggest names based on common conventions:
feature/email-notificationsfeat/email-notificationsadd-email-notifications
Switching Branches
Switch to the main branchClaude will:
- Check for uncommitted changes
- Prompt to save or stash changes if necessary
- Switch branches
- Confirm the switch succeeded
Merging Branches
Merge feature/user-profile into mainClaude will:
- Switch to the target branch
- Check for conflicts
- Execute the merge
- Provide resolution suggestions if there are conflicts
Handling Merge Conflicts
Identifying Conflicts
Check for merge conflictsClaude will list all files with conflicts and explain the nature of each conflict.
Resolving Conflicts
Help me resolve the merge conflict in src/config.tsClaude will:
- Show the conflicting content
- Analyze the differences between both versions
- Suggest a resolution
- Apply the resolution
- Mark the conflict as resolved
Complex Conflict Resolution
For complex conflicts:
This conflict involves refactoring and a new feature,
keep the new feature but use the refactored structureClaude will understand your intent and intelligently merge the code.
Code Review Workflow
Creating Pull Requests
Create a PR for the current branchClaude will:
- Push the current branch to remote
- Analyze the commit history
- Generate PR title and description
- Create the PR using GitHub CLI
PR Description Generation
Claude-generated PR descriptions typically include:
## Changes
- Add user profile page
- Implement avatar upload feature
- Add profile edit form
## Testing
- 95% unit test coverage
- Manual testing of all form validations
- Tested file upload limits
## Screenshots
[If applicable]
## Related Issues
Closes #123Reviewing Others' PRs
Review PR #456Claude will:
- Fetch the PR changes
- Analyze code quality
- Check for potential issues
- Provide improvement suggestions
- Generate review comments
History Management
Viewing Commit History
Show the last 10 commitsView the commit history for the src/auth/ directoryFinding Specific Changes
Find which commit introduced the User interfaceClaude will use git log and git blame to trace changes.
Reverting Changes
Revert the last commit but keep the changesClaude will use git reset --soft HEAD~1.
Completely undo the last commitClaude will use git reset --hard HEAD~1 (after confirming).
Stash Management
Saving Work in Progress
Stash current changes, I need to switch branchesClaude will:
- Run
git stash push - Add a descriptive message
- Confirm the stash succeeded
Restoring Work in Progress
Restore my previously stashed changesClaude will:
- List available stashes
- Apply the most recent stash
- Handle possible conflicts
Managing Multiple Stashes
List all stashesApply stash@{2}Remote Repository Operations
Pushing Changes
Push the current branch to remoteClaude will:
- Check remote branch status
- Push changes
- Handle possible conflicts
- Confirm the push succeeded
Pulling Updates
Pull latest changes from the main branchClaude will:
- Run
git pull - Handle merge conflicts (if any)
- Update the local branch
Syncing a Fork
Sync my fork with the upstream repositoryClaude will:
- Add the upstream remote (if not added)
- Fetch upstream changes
- Merge into the local branch
- Push to your fork
Git Best Practices
Atomic Commits
Claude encourages creating atomic commits:
Should these changes be split into multiple commits?Claude will analyze the changes and suggest logical groupings.
Pre-commit Checks
Before creating a commit, Claude will:
- Run linters
- Run tests
- Check code formatting
- Verify the build succeeds
Protecting Sensitive Information
Claude will detect and warn:
Warning: .env file contains sensitive information and should not be committed.
It has been added to .gitignore.Advanced Git Operations
Interactive Rebase
Clean up the last 5 commitsClaude will help you:
- Squash related commits
- Rewrite commit messages
- Reorder commits
- Remove unnecessary commits
Cherry-pick
Apply commit abc123 to the current branchClaude will:
- Execute the cherry-pick
- Handle conflicts
- Verify the result
Submodule Management
Add submodule https://github.com/user/repoUpdate all submodulesGit Hooks Integration
Pre-commit Hooks
Claude can help set up pre-commit hooks:
Set up a pre-commit hook to run linter and testsCommit Message Validation
Add a commit-msg hook to validate commit message formatTroubleshooting
Resolving Detached HEAD
I'm in a detached HEAD state, what should I do?Claude will:
- Explain the current state
- Provide recovery options
- Help create a new branch or return to the original branch
Recovering Lost Commits
I accidentally deleted a branch, how can I recover it?Claude will use git reflog to find the lost commits.
Cleaning the Repository
Clean up untracked files and directoriesClaude will:
- First show what will be deleted
- Execute cleanup after confirmation
- Use
git clean
Team Collaboration Patterns
Git Flow
Create a new feature branch using Git FlowClaude understands the Git Flow pattern and will:
- Create a feature branch from develop
- Follow naming conventions
- Merge back to develop when complete
GitHub Flow
Start a new feature using GitHub FlowClaude will:
- Create a branch from main
- Create a PR when development is complete
- Delete the branch after merging
Trunk-Based Development
Commit changes using the trunk-based patternClaude will:
- Create a short-lived branch
- Quickly merge to main
- Use feature flags to control functionality
Performance Optimization
Large Repository Handling
For large repositories, Claude will:
- Use shallow clones
- Enable sparse checkout
- Optimize Git configuration
Cleaning History
Reduce the repository sizeClaude will:
- Identify large files
- Use git-filter-repo to clean history
- Rewrite history (with confirmation)
Best Practices Checklist
- [ ] Run tests before committing
- [ ] Use descriptive commit messages
- [ ] Keep commits atomic
- [ ] Push to remote regularly
- [ ] Resolve merge conflicts promptly
- [ ] Don't commit sensitive information
- [ ] Use branches for feature development
- [ ] Review code before merging
- [ ] Keep commit history clean
- [ ] Sync remote changes regularly
With Claude Code's Git integration, you can manage version control more efficiently, focusing on writing code rather than memorizing Git commands.