AI-101

Lesson 12

Git Operations

AI Confidence: 90%

AI-generated

Git Operations

Learning Objectives

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

Introduction

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.

Committing Changes

After Claude makes changes (or after you make changes yourself), you can commit through Claude Code.

Simple commit:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude stages the files, generates a descriptive commit message based on what changed, and creates the commit.

With a specific message:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude uses your message instead of generating one.

Review before committing:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude shows you the current Git status so you can review before committing.

Asking for a descriptive message:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude analyzes the diff and writes a meaningful message. This is better than generic messages like "fix bug" because it describes what actually changed.

Creating Branches

Branch management is conversational:

Create a new branch:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude creates the branch and switches to it.

With a specific starting point:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Switch branches:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Check current branch:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude tells you the current branch and any uncommitted changes.

Creating Pull Requests

Claude Code can create pull requests directly. This works with GitHub, GitLab, and other Git hosting services.

Create a pull request:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude:

Summarizes your changes

Generates a title and description

Creates the pull request

Returns the URL so you can view it

With more detail:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude writes a more thorough PR description based on your commits.

Step by step:

If you want more control:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Review the summary, then:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

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.

Linking Sessions to PRs

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:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

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

Resolving Merge Conflicts

Merge conflicts are frustrating. Claude Code can help.

When you have conflicts:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude reads the conflicted files, understands both sides, and suggests resolutions. You review and approve each resolution.

Understanding the conflict:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude explains what changed on each side and why they conflict.

Step by step resolution:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude shows the specific conflicts. You can discuss each one and decide how to resolve it.

After resolving:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude handles the Git mechanics.

Other Git Operations

Claude Code handles many Git tasks:

View history:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

View diffs:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Stash changes:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Reset and restore:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
Git Best Practices with Claude

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.

Working with GitHub Actions

Claude Code integrates with GitHub Actions for automated workflows:

Install the GitHub app:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

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.

Key Takeaways

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

Try It Yourself

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.

Sources

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