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¶
Claude runs git status and explains:
- Which files are modified
- Which are staged
- Which are untracked
View 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¶
Claude will:
1. Check git status
2. Review the changes
3. Suggest a commit message
4. Ask for confirmation
Specific Files¶
With a Message¶
Staged vs Unstaged¶
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¶
Switch Branches¶
Branch Status¶
Merge¶
Creating Pull Requests¶
Claude can create PRs using the GitHub CLI (gh):
Claude will: 1. Check your branch status 2. Review all commits 3. Generate a summary 4. Create the PR with a description
With Details¶
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¶
Claude examines: - Changed files - Logic correctness - Potential issues - Style consistency
Review Specific Concerns¶
Respond to Review Comments¶
Claude reads comments and suggests fixes.
Handling Conflicts¶
Identify Conflicts¶
Resolve Conflicts¶
Verify Resolution¶
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¶
Compare Versions¶
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¶
Safety Features¶
Claude Code has built-in safety measures:
Won't Force Push to Main¶
Claude will refuse or warn strongly.Verifies Before Destructive Operations¶
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¶
-
Initialize a new repo:
-
Create initial files:
-
Make the first commit:
-
Create a feature branch:
-
Implement and commit:
-
Check your history:
Exercise: Simulated PR Review¶
- Ask Claude to create a file with subtle bugs
- Commit it
- Ask Claude to review the changes as if it were a PR
- Fix issues based on the review
- 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¶
Featured Video¶
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 |