Lesson 12
Git Operations
AI-generated
Git Operations
Commit changes with descriptive messages through Claude Code
Create and manage branches conversationally
Create pull requests directly from your session
Get help resolving merge conflicts
Link sessions to pull requests for easy resumption
Claude Code understands Git. You do not need to memorize Git commands or syntax. Just describe what you want in plain English, and Claude handles the Git operations for you.
This goes beyond simple commits. Claude can create branches, open pull requests, and help you resolve merge conflicts. All through conversation, all without leaving Claude Code.
This lesson covers the Git workflows you will use most often. By the end, you will be able to manage your entire Git workflow through natural language.
After Claude makes changes (or after you make changes yourself), you can commit through Claude Code.
Simple commit:
Claude stages the files, generates a descriptive commit message based on what changed, and creates the commit.
With a specific message:
Claude uses your message instead of generating one.
Review before committing:
Claude shows you the current Git status so you can review before committing.
Asking for a descriptive message:
Claude analyzes the diff and writes a meaningful message. This is better than generic messages like "fix bug" because it describes what actually changed.
Branch management is conversational:
Create a new branch:
Claude creates the branch and switches to it.
With a specific starting point:
Switch branches:
Check current branch:
Claude tells you the current branch and any uncommitted changes.
Claude Code can create pull requests directly. This works with GitHub, GitLab, and other Git hosting services.
Create a pull request:
Claude:
Summarizes your changes
Generates a title and description
Creates the pull request
Returns the URL so you can view it
With more detail:
Claude writes a more thorough PR description based on your commits.
Step by step:
If you want more control:
Review the summary, then:
GitHub CLI required:
Creating pull requests uses the gh CLI tool. If you do not have it installed, Claude will tell you. Install it from https://cli.github.com and authenticate with gh auth login.
When you create a PR through Claude Code, the session is automatically linked to that PR. This helps you resume work later.
Resume from a PR:
This opens sessions that are linked to PR #123. You continue exactly where you left off when working on that PR.
This is useful for:
Returning to a PR after time away
Addressing review comments
Making follow-up changes
Merge conflicts are frustrating. Claude Code can help.
When you have conflicts:
Claude reads the conflicted files, understands both sides, and suggests resolutions. You review and approve each resolution.
Understanding the conflict:
Claude explains what changed on each side and why they conflict.
Step by step resolution:
Claude shows the specific conflicts. You can discuss each one and decide how to resolve it.
After resolving:
Claude handles the Git mechanics.
Claude Code handles many Git tasks:
View history:
View diffs:
Stash changes:
Reset and restore:
Commit frequently. After each logical change that works, commit. This gives you restore points.
Use descriptive messages. Let Claude generate messages based on your changes. They will be more accurate than generic messages.
Branch for features. Create branches for new work. This keeps main clean and makes PRs cleaner.
Review before pushing. Ask Claude to summarize your changes before creating a PR. Make sure everything is intentional.
Commit before clearing. If you have uncommitted changes and want to /clear, commit first. Otherwise you might forget what changed.
Claude Code integrates with GitHub Actions for automated workflows:
Install the GitHub app:
This walks you through setting up Claude Code as a GitHub Action in your repository.
What you can automate:
Automated PR reviews
Issue triage
Code generation from issues
Automated testing feedback
We cover CI/CD integration in detail in a later lesson.
Commit changes with "commit my changes" and Claude generates descriptive messages
Create branches with "create a branch called [name]"
Create pull requests with "create a pr" using the GitHub CLI
Sessions link to PRs automatically for easy resumption
Claude helps resolve merge conflicts by explaining and suggesting resolutions
All Git operations work through natural language conversation
Practice Git operations with these steps:
Start Claude Code in a Git repository.
Ask "what branch am I on?" and "what files have changed?"
Make a small change to a file through Claude.
Ask Claude to "commit my changes with a descriptive message."
Create a new branch: "create a branch called test-branch."
Make another change and commit it.
Ask "what's different between main and this branch?"
If you have the GitHub CLI installed, try "create a pr."
This exercise covers the core Git workflow.
https://code.claude.com/docs/en/common-workflows - Git operations and PR creation
https://code.claude.com/docs/en/quickstart - Basic commit and branch commands
https://code.claude.com/docs/en/github-actions - GitHub Actions integration