Skip to content

Using Copilot to Work with Git

Shane Neuville edited this page Dec 8, 2025 · 1 revision

GitHub Copilot can help you with git operations, making version control faster and more intuitive. This guide shows you how to use Copilot for common git tasks in the .NET MAUI repository.

Quick Start

Simply ask Copilot what you want to do:

commit my changes
squash all my commits into one with a good commit message
rebase this branch with main and fix any merge conflicts

Copilot will handle the git commands and provide clear, descriptive commit messages automatically.


Committing Changes

Let Copilot Write Your Commit Message

Instead of manually writing commit messages, let Copilot analyze your changes:

commit my changes

What Copilot does:

  • Analyzes your staged changes
  • Generates a conventional commit message
  • Includes relevant issue numbers if found
  • Creates a descriptive summary of the changes

Example commit message Copilot generates:

fix(CollectionView): prevent crash when removing last item

- Added null check in CollectionViewHandler.OnItemRemoved
- Updated adapter before notifying item removal
- Ensures item count is validated before access
- Fixes #12345

Commit with Context

Provide context for better commit messages:

commit my changes as a fix for issue #12345
commit these changes explaining why the SafeArea calculation changed
stage and commit my bug fix for the Android keyboard issue

Squashing Commits

When you have multiple work-in-progress commits that should be one logical change, Copilot can squash them with a comprehensive message.

Basic Squash

squash all my commits into one with a good commit message

Before squashing:

* wip
* fix typo
* add test
* fix test
* address review comments

After squashing (Copilot generates this):

feat(CollectionView): add item selection support

- Implemented SelectionMode property (Single/Multiple)
- Added SelectedItem and SelectedItems bindable properties
- Added SelectionChanged event with detailed event args
- Includes comprehensive UI tests for both platforms
- Added documentation for selection APIs
- Fixes #12345

Squash Specific Commits

squash the last 3 commits
squash all commits since I branched from main
combine my last 5 commits with a meaningful message

Rebasing

Rebase with Main

Keep your branch up to date:

rebase this branch with main
update my branch with the latest from main

Rebase and Resolve Conflicts

Let Copilot help resolve merge conflicts:

rebase this branch with main and fix any merge conflicts

What Copilot does:

  1. Performs the rebase
  2. Identifies conflicts
  3. Analyzes both versions
  4. Suggests the correct resolution based on context
  5. Applies the fix and continues

Example conflict Copilot resolves:

<<<<<<< HEAD (main)
public void UpdateItems()
{
    _adapter.UpdateItems(_items);
    NotifyDataSetChanged();
}
=======
public void UpdateItems()
{
    if (_adapter != null)
        _adapter.SetItems(_items);
}
>>>>>>> your-branch

Copilot combines them intelligently:

public void UpdateItems()
{
    if (_adapter != null)
    {
        _adapter.UpdateItems(_items);
        NotifyDataSetChanged();
    }
}

Understanding Changes

Review What Changed

what changed in the last commit?
explain my current uncommitted changes
summarize all changes in this branch

Copilot provides:

  • File-by-file breakdown
  • Explanation of modifications
  • Impact on other code
  • Why the changes were needed

Compare with Main

what's different between my branch and main?
show me what I changed compared to main
list all the files I modified in this branch

Creating Pull Requests

Generate PR Description

create a PR description for my changes
write a pull request description

Copilot generates:

## Summary
Fixes crash in CollectionView when removing the last item from an adapter with a single element.

## Problem
CollectionView crashed with IndexOutOfBoundsException when:
- Adapter contains exactly one item
- User removes that item
- Handler tries to notify adapter before checking count

## Solution
- Added validation in `CollectionViewHandler.OnItemRemoved`
- Check adapter item count before notifying changes
- Update adapter state before triggering UI updates

## Testing
- ✅ Tested on Android API 34 emulator
- ✅ Tested on iOS 17.5 simulator  
- ✅ Added UI test `Issue12345.cs` that reproduces the crash
- ✅ Verified fix works with 0, 1, and multiple items

## Related Issues
Fixes #12345

## Checklist
- [x] Code follows .NET MAUI conventions
- [x] Added/updated tests
- [x] Ran `dotnet format`
- [x] Updated PublicAPI.Unshipped.txt (if needed)
- [x] Tested on multiple platforms

Customize PR Description

create a PR description focusing on the performance improvements
write a PR description that explains the technical approach in detail

Branch Management

Create and Switch Branches

create a new branch called fix/collectionview-crash
switch to branch main
create a branch for issue #12345

Clean Up Branches

delete my local branch after it's been merged
list all my local branches

Checking Repository Status

Quick Status Check

show me what's changed
what files did I modify?
are there any uncommitted changes?

View History

show me the last 5 commits
who changed this file recently?
when was CollectionViewHandler.cs last modified?

Undoing Changes

Revert Changes

undo my changes to MainPage.xaml
discard all uncommitted changes
revert the last commit but keep the changes

Unstage Files

unstage all my changes
remove CollectionView.cs from staging

Best Practices

1. Stage Changes First

Copilot works best when you've already staged the files you want to commit:

# Stage your changes first
git add src/Controls/CollectionView/

# Then ask Copilot to commit
commit my CollectionView changes

2. Be Specific

Instead of:

help with git

Try:

commit my SafeArea fixes with a message explaining the iOS keyboard issue

3. Review Before Accepting

Always review what Copilot suggests:

  • ✅ Read the commit message - does it accurately describe your changes?
  • ✅ Check conflict resolutions - did it preserve the correct logic?
  • ✅ Verify squashed commits - did it capture all important details?

4. Iterate if Needed

If the first result isn't perfect:

You: commit my changes

Copilot: "fix: update handler"

You: make that commit message more descriptive

Copilot: "fix(CollectionView): prevent crash when removing last item from empty adapter

- Added null check in OnItemRemoved
- Fixes #12345"

Conventional Commit Format

Copilot automatically generates commits following the Conventional Commits standard:

<type>(<scope>): <description>

[optional body]

[optional footer]

Common Types

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation only
  • test: Adding or updating tests
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Performance improvement
  • chore: Maintenance tasks
  • ci: CI/CD changes

Examples

feat(CollectionView): add item selection support

fix(SafeArea): correct padding calculation for iOS keyboard

test(CollectionView): add regression test for item removal

docs(README): update build instructions

refactor(Handlers): simplify adapter initialization

perf(Layout): optimize measure pass for nested layouts

When to Squash Commits

✅ Good Times to Squash

  • Before merging a PR - Clean up your commit history
  • Multiple "wip" commits - Combine into logical changes
  • Addressing review feedback - Squash fixup commits into the original
  • Experimental work - Consolidate trial-and-error into clean commits

❌ Bad Times to Squash

  • Commits represent distinct features - Keep them separate
  • Others based work on your commits - Don't rewrite shared history
  • Debugging requires history - Individual commits provide context
  • Required by team workflow - Follow your team's practices

Common Prompts Quick Reference

What You Want What to Say
Commit changes commit my changes
Commit with context commit my changes for issue #12345
Squash everything squash all my commits with a good message
Squash last N squash my last 3 commits
Rebase with main rebase this branch with main
Fix conflicts rebase with main and resolve conflicts
Review changes what changed in the last commit?
Create PR create a PR description
Create branch create a new branch for issue #12345
Undo changes discard my changes to this file

Tips for Success

1. Use Clear Branch Names

Good branch names help Copilot understand context:

  • fix/collectionview-crash-12345
  • feat/add-selection-support
  • stuff
  • temp123

2. Commit Frequently

Smaller, frequent commits are easier for Copilot to describe accurately than large, monolithic commits.

3. Stage Intentionally

Stage related changes together:

# Good - related changes together
git add src/Controls/CollectionView/*

# Less ideal - unrelated changes
git add .

4. Reference Issues

Mention issue numbers when committing:

commit these changes as a fix for issue #12345

This helps Copilot include proper issue references in the commit message.

5. Ask for Explanations

If you're unsure about a git operation:

what does rebasing do?
explain the difference between merge and rebase
what will happen if I squash these commits?

Advanced Workflows

Interactive Rebase

start an interactive rebase for the last 5 commits
help me clean up my commit history

Cherry-Pick

cherry-pick commit abc123 to this branch
apply the changes from that commit to my current branch

Stashing

stash my current changes
apply my stashed changes
list all my stashes

Troubleshooting

"I committed to the wrong branch"

move my last commit to a new branch

"I need to undo a commit"

undo my last commit but keep the changes

"I have merge conflicts I don't understand"

explain these merge conflicts and help me resolve them

"My commit message was wrong"

amend my last commit message

Resources

Clone this wiki locally