Skip to main content

Lesson 9: Git Integration

Learning Objectives

After completing this lesson, you will be able to:

  • Use Claude for git operations
  • Create meaningful commits with /commit
  • Generate pull requests with /pr
  • Search git history effectively
  • Work with GitHub PRs and issues
  • Understand attribution settings

Prerequisites

  • Completed Lessons 1-8 - Core operations and advanced features
  • Git installed - Basic git knowledge helpful
  • GitHub account - For PR workflows (optional but recommended)

Estimated Time: 25 minutes


Git Operations with Claude

Claude Code makes git workflows seamless by combining AI intelligence with version control.

Why Use Claude for Git?

Smarter commits:

  • Understands what changed
  • Writes meaningful commit messages
  • Follows conventional commit format

Safer operations:

  • Reviews changes before committing
  • Explains what will be committed
  • Prevents accidental commits

Better workflows:

  • Integrates with your conversation
  • Context-aware commit messages
  • Automated PR creation

Basic Git Workflow with Claude

Traditional workflow:

git status
git add .
git commit -m "fix bug"
git push

With Claude:

You> /commit

Claude handles everything intelligently!


The /commit Skill

The /commit skill is the most common way to create commits with Claude.

How /commit Works

Step 1: Analyze changes

You> /commit

Claude: Let me check what's changed...

[Uses Bash: git status]

Modified files:
- src/auth.py
- src/api/user.py
- tests/test_auth.py

Step 2: Review diffs

Claude: [Reading the changes...]

Changes:
✏️ src/auth.py: Added JWT token validation
✏️ src/api/user.py: Fixed user creation endpoint
✏️ tests/test_auth.py: Added tests for token validation

These changes look related to authentication improvements.

Step 3: Generate commit message

Claude: I'll create a commit with this message:

feat(auth): add JWT token validation and fix user creation

- Add JWT token validation to auth service
- Fix user creation endpoint error handling
- Add comprehensive tests for token validation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Proceed? [Y/n]

Step 4: Create commit

[Uses Bash: git add]
[Uses Bash: git commit]

✓ Commit created: a1b2c3d

Commit Message Formats

Claude follows Conventional Commits format:

<type>(<scope>): <subject>

<body>

<footer>

Types:

  • feat - New feature
  • fix - Bug fix
  • docs - Documentation changes
  • style - Code style (formatting, etc.)
  • refactor - Code refactoring
  • test - Adding/updating tests
  • chore - Maintenance tasks

Example:

feat(auth): add OAuth2 login support

Implement OAuth2 authentication flow with:
- Google OAuth provider
- Token refresh mechanism
- User profile synchronization

Closes #123

Custom Commit Messages

Provide your own message:

You> /commit -m "Add login feature"

Edit Claude's suggestion:

You> /commit

Claude: [Proposes message]

You: Use "feat: implement user authentication" instead

Claude: Updated commit message. Proceed? [Y/n]

Interact to refine:

You> /commit

Claude: [Proposes message]

You: Make it more detailed. Mention the security improvements.

Claude: [Updates message with more detail]

Creating Pull Requests with /pr

The /pr skill automates pull request creation.

How /pr Works

Step 1: Analyze branch

You> /pr

Claude: Let me prepare a pull request...

[Checks git status]
[Checks branch name]
[Compares to main branch]

Step 2: Review commits

Claude: Found 3 commits in this branch:

1. feat: add authentication
2. fix: correct login bug
3. docs: update API documentation

Base branch: main
Feature branch: feature/user-auth

Step 3: Generate PR description

Claude: I'll create a PR with:

Title: feat: Add user authentication system

Summary:
Implements complete user authentication with JWT tokens.

Changes:
- Add login/logout endpoints
- Implement JWT token generation
- Add authentication middleware
- Create user registration flow
- Add comprehensive tests

Test plan:
- [x] Unit tests pass
- [x] Manual testing completed
- [ ] Code review approved

Closes #45

Step 4: Create PR

Claude: Create this PR? [Y/n]
You: Y

[Uses Bash: git push]
[Uses GitHub MCP or gh CLI]

✓ PR created: https://github.com/user/repo/pull/46

PR Best Practices with Claude

Be specific in conversation:

You> Create a PR for the authentication feature. Mention that it
closes issue #45 and includes the security improvements we discussed.

Include test information:

You> Generate a PR. Note that all tests pass and we've manually tested
the login flow.

Link to issues:

You> /pr and close #123 and #124

Searching Git History

Claude can search and analyze git history intelligently.

Searching by Content

You> When was the login function added?

Claude: [Searches git log]

The login function was added in commit 1a2b3c4 on March 15, 2024:

feat(auth): add user login

Added login endpoint with email/password authentication.

Searching by Author

You> What commits did I make yesterday?

Claude: [Searches git log by author and date]

Found 3 commits from you yesterday:
- fix(api): correct error handling (2h ago)
- feat: add user preferences (5h ago)
- docs: update README (8h ago)

Searching by File

You> What's the history of src/auth.py?

Claude: [Searches file history]

src/auth.py has been modified 12 times:
- Latest: Added JWT support (2 days ago)
- Previous: Fixed token bug (1 week ago)
- Original: Initial auth implementation (3 months ago)

Understanding Changes

You> What changed between v1.0 and v1.1?

Claude: [Compares tags/tags]

Changes between v1.0 and v1.1:

New features:
- User authentication
- Dark mode
- Export functionality

Bug fixes:
- Fixed memory leak in image processing
- Corrected date formatting

Breaking changes:
- Configuration file format changed
- API endpoint structure updated

Working with GitHub PRs

Claude integrates with GitHub to review and manage pull requests.

Viewing PR Details

You> Show me PR #42

Claude: [Uses GitHub MCP]

Pull Request #42: Add notification system

Status: ✓ Open
Author: @devuser
Created: 2 days ago
Reviewers: @senior-dev

Changes:
- +245 lines added
- -12 lines removed
- 8 files modified

Description:
Implements real-time notification system with:
- Email notifications
- In-app notifications
- Notification preferences

Code Review with Claude

You> Review the changes in PR #42

Claude: [Fetches PR diff]

Review of PR #42:

Strengths:
✓ Well-structured code
✓ Comprehensive tests added
✓ Good error handling

Concerns:
⚠ Missing input validation on notification preferences
⚠ No rate limiting on email notifications
⚠ Potential N+1 query in notification fetching

Recommendations:
1. Add validation for preference values
2. Implement rate limiting
3. Use eager loading for notifications

Overall: Approve with minor changes suggested

Applying PR Changes Locally

You> Fetch and apply PR #42 locally

Claude: [Uses git commands]

Fetching PR...
Merging into local branch...

✓ PR #42 changes applied to your working directory

Attribution Settings

Claude Code includes proper attribution for AI-assisted commits.

What is Attribution?

Attribution credits Claude's contributions in commits.

Default format:

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Example commit:

feat: add user authentication

Added JWT-based authentication with email/password login.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Configuring Attribution

In settings file:

{
"git": {
"attribution": {
"enabled": true,
"format": "Co-Authored-By: {model} <noreply@anthropic.com>"
}
}
}

Disable attribution:

{
"git": {
"attribution": {
"enabled": false
}
}
}

Custom format:

{
"git": {
"attribution": {
"format": "Assisted by Claude ({model})"
}
}
}

Why Attribution Matters

Transparency:

  • Shows AI involvement
  • Maintains git history integrity
  • Credits AI contributions

Collaboration:

  • Team knows AI assisted
  • Maintains trust
  • Clear contribution record

Compliance:

  • Some organizations require disclosure
  • Maintains ethical standards
  • Follows best practices

Practical Example: Complete Git Workflow

Let's walk through a real git workflow with Claude.

Scenario: Add a New Feature

Step 1: Create feature branch

You> Create a new branch called feature/user-dashboard

Claude: [Uses git checkout -b]

✓ Branch created and checked out: feature/user-dashboard

Step 2: Make changes

You> Create a user dashboard component with stats and charts

[Claude creates files]

Step 3: Review changes

You> What files have changed?

Claude: [Uses git status]

Modified:
+ src/components/Dashboard.jsx (new)
+ src/api/stats.js (new)
+ src/styles/dashboard.css (new)

Step 4: Commit changes

You> /commit

Claude: I'll commit these changes:

feat(dashboard): add user dashboard with statistics

Implemented new dashboard component featuring:
- User statistics display
- Interactive charts
- Recent activity feed
- Quick actions panel

Files changed:
- Dashboard component
- Stats API integration
- Dashboard styling

Proceed? [Y/n]
You: Y

✓ Commit created

Step 5: Make additional changes

You> Add a dark mode toggle to the dashboard

[Claude updates files]

Step 6: Commit again

You> /commit

✓ Commit created: feat(dashboard): add dark mode toggle

Step 7: Push to remote

You> Push this branch

Claude: [Uses git push]

✓ Pushed to origin/feature/user-dashboard

Step 8: Create PR

You> /pr

Claude: I'll create a pull request...

Title: feat: Add user dashboard with dark mode

Summary:
Implements comprehensive user dashboard with:
- Statistics and analytics
- Interactive data visualization
- Dark mode support
- Responsive design

Commits:
- feat(dashboard): add user dashboard with statistics
- feat(dashboard): add dark mode toggle

Test Plan:
✓ Tested on Chrome, Firefox, Safari
✓ Verified responsive design
✓ Tested dark mode toggle
✓ All unit tests passing

Create PR? [Y/n]
You: Y

✓ PR created: https://github.com/user/repo/pull/78

✅ Check Your Understanding

  1. What skill creates commits automatically?

    • /save
    • /commit
    • /git
    • /store
  2. What commit format does Claude use by default?

    • Angular commits
    • Conventional commits
    • Git flow commits
    • Custom format
  3. Which skill creates pull requests?

    • /pr
    • /pull-request
    • /request
    • /merge
  4. True or False: Claude can search git history for specific changes.**

    • True
    • False
  5. What does attribution do?

    • Tags releases
    • Credits Claude's contributions in commits
    • Manages branches
    • Creates backups

Answers: 1-b, 2-b, 3-a, 4-True, 5-b


Summary

In this lesson, you learned:

  • Git with Claude - Smarter, safer git operations
  • /commit skill - Automatic meaningful commits
  • /pr skill - Automated pull request creation
  • Git history search - Find changes by content, author, file
  • GitHub PRs - Review and manage pull requests
  • Attribution - Credit AI contributions properly

Next Steps

In Lesson 10: IDE Integration, you'll learn:

  • VS Code extension features
  • JetBrains plugin capabilities
  • Desktop app functionality
  • Browser automation with Chrome extension
  • Switching between interfaces

Further Reading


Continue to Lesson 10: IDE Integration