## Executive Summary

Version control is the operational backbone of modern software development. In this deep-dive session, Sebastian Hernandez demonstrated how Visual Studio 2026 empowers developers to execute their entire lifecycle—from parallel worktree branching and submodule maintenance to AI-driven feature authoring, local pre-PR diff code reviews, AI-assisted merge conflict resolution, and in-IDE pull request voting—without ever leaving Visual Studio or touching external Git GUI clients.

![Get the Most Out of Git in Visual Studio](/dotnetconf2026/archive/21-git-in-visual-studio/screenshots/01_title_git_in_vs.webp)

### End-to-End Git Workflow in Visual Studio

```mermaid
flowchart TD
    A[Environment Setup<br/>Git Worktrees & Submodules] --> B[AI Feature Development<br/>Copilot Chat & Commit Context]
    B --> C[Local Code Review<br/>Multi-file diffs & inline review threads]
    C --> D[Commit Organizing & Rebase<br/>AI story structuring]
    D --> E[Conflict Resolution<br/>Bulk operations & AI Auto-Resolve]
    E --> F[In-IDE Pull Request<br/>Semantic Grouping, Voting & Checkout Editing]
```

![Git Workflow Agenda](/dotnetconf2026/archive/21-git-in-visual-studio/screenshots/02_git_workflow_agenda_slide.webp)

---

## 1. Version Control Environment: Git Worktrees & Submodules

As multi-agent workflows and concurrent feature development become standard, traditional branch switching (`git stash` -> `git checkout`) creates heavy build cache invalidation and IDE reload friction.

![Git Worktrees Management](/dotnetconf2026/archive/21-git-in-visual-studio/screenshots/03_git_worktrees_management.webp)

### First-Class Git Worktrees
- **Dedicated Tree Visualization:** In the Git Repository tool window, branches bound to active worktrees display dedicated worktree badges and directories.
- **Context Menu Creation:** Right-clicking any branch exposes `Create New Worktree...`, prompting for a directory name with options to open immediately in the active window or spawn a decoupled background Visual Studio instance.
- **Multi-Instance Concurrency:** Enables running autonomous agents or long-running builds in one worktree while continuing interactive feature development in another worktree without repository locks.
- **Lifecycle Cleanup:** One-click deletion and pruning of completed worktrees directly from the UI.

### Git Submodule Management
- **Status & Revision Tracking:** Submodule nodes appear directly in the repository graph, displaying the currently checked-out commit SHA and dirty state.
- **Update & Maintenance:** Right-click context actions allow updating submodules to the latest tracked upstream commit or cleanly removing obsolete submodules.

![Git Submodules Support](/dotnetconf2026/archive/21-git-in-visual-studio/screenshots/04_git_submodules_support.webp)

---

## 2. Feature Implementation with Copilot Commit Context

Sebastian demonstrated a real-world scenario extending the Visual Studio Version Control tool window itself: bringing the popular `Add to Chat` context verb from the historical commit log into the pull request commit inspector.

![Add Commit to Chat Context](/dotnetconf2026/archive/21-git-in-visual-studio/screenshots/05_add_commit_to_chat_context.webp)

### Driving Copilot with Commit Grounding
- Right-clicking any historical commit allows selecting `Add to Chat`.
- This attaches the exact commit SHA, commit message, author metadata, and touched file diffs into Copilot's working memory as grounding context.
- Sebastian prompted Copilot: *"In the history view, we allow adding commits to chat via command services. Implement this identical capability in the Pull Request code review commit inspector."*
- Copilot generated the implementation across command bindings, UI definitions, and service registrations.
- **Verification:** Launching the experimental Visual Studio instance (`Ctrl+F5`) confirmed the new `Add to Chat` context verb immediately appeared and functioned inside the Pull Request tool window.

![Experimental VS Instance PR Commit Chat](/dotnetconf2026/archive/21-git-in-visual-studio/screenshots/06_experimental_vs_instance_pr_commit_chat.webp)

---

## 3. Local Pre-PR Code Review & Inline AI Discussion

Before publishing code to team pull requests, Visual Studio provides a local code review surface:

### Review Changes Since Commit
- Right-clicking the base commit and selecting `Review changes since this commit` opens a comprehensive multi-file summary diff.
- Developers can review AI-generated code line-by-line, leaving inline comments and questions.
- **Interactive AI Questioning:** Sebastian left an inline comment on an unfamiliar dependency: *"Why did we add this dependency?"*
- Prompting Copilot Chat with *"Respond to my local review comments"* caused the agent to locate the active discussion thread, inspect the dependency graph, and post an explanatory response directly into the inline comment bubble.

![Copilot Responding to Review Thread](/dotnetconf2026/archive/21-git-in-visual-studio/screenshots/08_copilot_responding_to_review_thread.webp)

---

## 4. Organizing Commits & AI-Assisted Merge Conflicts

### AI Commit Structuring
Rather than submitting monolithic, messy commits, developers can prompt Copilot: *"Break down these staged modifications into a logical sequence of commits telling a clear what, how, and why story."* Copilot recommended a 3-stage breakdown isolating data contracts, command bindings, and UI registrations.

### Fast Conflict Resolution & AI Auto-Resolve
When rebasing the feature branch onto `main`, merge conflicts arose. Visual Studio 2026 introduces major conflict tooling:

![Merge Conflict Bulk Actions](/dotnetconf2026/archive/21-git-in-visual-studio/screenshots/09_merge_conflict_bulk_actions.webp)

- **Bulk Node Resolution:** Right-clicking the parent conflict node allows instantly selecting `Take All Changes from Main` (Incoming) or `Take All Changes from Feature` (Current) without stepping through dozens of files individually.
- **3-Way Merge Editor:** Side-by-side visualization of Incoming, Current, and Resulting buffers with inline conflict gutters.
- **Auto Resolve with AI:** Clicking the `Auto Resolve` button hands the conflict over to Copilot. Copilot locks file editing, analyzes the semantic intent of both branches, merges the changes safely, and automatically triggers an MSBuild compilation to verify there are no compilation errors.
- **Conflict Restart Dropdown:** If an automated resolution is unsatisfactory, the `Accept Merge` dropdown provides an instant `Restart Resolution Completely` fallback.

![AI Auto-Resolve Merge Conflicts](/dotnetconf2026/archive/21-git-in-visual-studio/screenshots/10_ai_auto_resolve_merge_conflicts.webp)

---

## 5. In-IDE Pull Request Management & Semantic Review

Visual Studio 2026 provides a first-class Pull Request hub supporting both **GitHub** and **Azure DevOps**:

### Complete PR Lifecycle
- **Authoring & Overview:** Create PRs with AI-generated markdown summaries, embedded animated gifs, architectural diagrams, work item links, and designated reviewers.
- **Reviewer Governance:** Cast review votes directly in the IDE (`Approve`, `Approve with Suggestions`, `Wait for Author`, `Reject`) and configure auto-complete policies.

![AI Semantic Change Groupings and Checkout](/dotnetconf2026/archive/21-git-in-visual-studio/screenshots/12_ai_semantic_change_groupings_checkout.webp)

### AI Semantic Change Groupings
For large PRs with dozens of modified files, the **Generate Groups** AI button clusters touched files into logical semantic buckets:
- Core contracts and interfaces
- Service layer business logic
- Configuration and dependency updates
- Test suites

### Live Checkout & In-Place Diff Editing
Clicking `Check out Pull Request` checks out the author's remote branch locally. This unlocks a unique capability: **direct in-place editing inside the PR review diff window**. Rather than switching to code editor tabs to address minor reviewer nit comments, developers can edit code directly in the diff gutter, save, reply to the comment thread, and push immediately.
