Skip to content

Git Workflows

Learn how Claude Code integrates with Git for version control.

What You'll Learn

  • Checking status and history
  • Creating commits
  • Working with branches
  • Creating pull requests
  • Code review assistance

Checking Status

Current State

> What's the git status?

Claude runs git status and explains: - Which files are modified - Which are staged - Which are untracked

View Changes

> Show me what I've changed

> What's the diff for src/auth.js?

> Show me all unstaged changes

History

> Show me the last 10 commits

> What changed in the last commit?

> Find commits that touched the User model

Creating Commits

Basic Commit

> Commit my changes with an appropriate message

Claude will: 1. Check git status 2. Review the changes 3. Suggest a commit message 4. Ask for confirmation

Specific Files

> Commit only the changes to auth.js

With a Message

> Commit these changes with message "Fix login validation bug"

Staged vs Unstaged

> Stage the test files and commit them separately

Commit Message Guidelines

Claude follows these conventions:

type(scope): brief description

Longer explanation if needed.

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>

Types

Type Use
feat New feature
fix Bug fix
docs Documentation
refactor Code restructure
test Adding tests
chore Maintenance

Examples

feat(auth): add password reset flow

fix(api): handle null user in getProfile

refactor(utils): simplify date formatting logic

Working with Branches

Create a Branch

> Create a branch called feature/user-settings

Switch Branches

> Switch to the main branch

> Go back to the branch I was on

Branch Status

> What branch am I on?

> How many commits ahead of main am I?

> Show me all branches

Merge

> Merge main into my current branch

Creating Pull Requests

Claude can create PRs using the GitHub CLI (gh):

> Create a pull request for my changes

Claude will: 1. Check your branch status 2. Review all commits 3. Generate a summary 4. Create the PR with a description

With Details

> Create a PR with title "Add user settings page"

Template

Claude generates PRs in this format:

## Summary
- What the PR does
- Key changes

## Test plan
- [ ] How to test
- [ ] Edge cases checked

🤖 Generated with Claude Code

Code Review

Review a PR

> Review PR #123

Claude examines: - Changed files - Logic correctness - Potential issues - Style consistency

Review Specific Concerns

> Review the security implications of PR #45

> Does PR #78 have good test coverage?

Respond to Review Comments

> Address the review comments on my PR

Claude reads comments and suggests fixes.

Handling Conflicts

Identify Conflicts

> I tried to merge but got conflicts. Help me resolve them.

Resolve Conflicts

> In auth.js, keep both the new validation and the error handling

Verify Resolution

> Check that my conflict resolution makes sense

Git Investigation

Find When Something Changed

> When was the login function last modified?

> Who wrote the User model?

> What commit introduced this bug?

Understand History

> Summarize what changed in the auth module over the last month

Compare Versions

> What's different between v1.0 and v2.0?

Workflow Examples

Feature Development

> Create a branch for adding dark mode

> [work on feature...]

> Commit my changes

> [more work...]

> Commit again

> Create a PR to main

Bug Fix

> Create a branch called fix/login-error

> [implement fix...]

> Commit with message "Fix: handle null user in login flow"

> Create a PR

Keeping Up to Date

> Fetch the latest from origin

> Am I behind main?

> Rebase my changes on top of main

Safety Features

Claude Code has built-in safety measures:

Won't Force Push to Main

> Push --force to main
Claude will refuse or warn strongly.

Verifies Before Destructive Operations

> Reset to the previous commit
Claude confirms what will be lost.

Preserves Authorship

When amending commits, Claude checks that it's not modifying others' work.

Try It Yourself

Exercise: Git Workflow Practice

  1. Initialize a new repo:

    mkdir git-practice && cd git-practice
    git init
    claude
    

  2. Create initial files:

    > Create a simple Python calculator and README
    

  3. Make the first commit:

    > Commit these files
    

  4. Create a feature branch:

    > Create a branch for adding a square root function
    

  5. Implement and commit:

    > Add a square root function to calculator.py
    
    > Commit this change
    

  6. Check your history:

    > Show me the commit log
    

Exercise: Simulated PR Review

  1. Ask Claude to create a file with subtle bugs
  2. Commit it
  3. Ask Claude to review the changes as if it were a PR
  4. Fix issues based on the review
  5. Create a new commit

What's Next?

Learn about writing and running tests in 04-testing.


Summary: - Claude can check status, create commits, and manage branches - Commit messages follow conventional format - PRs are created with summaries and test plans - Claude helps with code review and conflict resolution - Safety features prevent dangerous git operations


Learning Resources

GitHub: GitHub for Beginners Series (Official GitHub channel)

Git integration with AI assistants - commits, branches, PRs, and code review workflows.

Additional Resources

Type Resource Description
🎬 Video Git & GitHub Tutorial Complete git workflow guide
📚 Official Docs GitHub Integration Claude Code GitHub documentation
📖 Tutorial GitHub AI Integration AI-Git workflow patterns
🎓 Free Course GitHub Copilot Tutorials Official free tutorials
💼 Commercial Git Complete Course Comprehensive git mastery