-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Using Copilot to Work with Git
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.
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.
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
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
When you have multiple work-in-progress commits that should be one logical change, Copilot can squash them with a comprehensive message.
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 the last 3 commits
squash all commits since I branched from main
combine my last 5 commits with a meaningful message
Keep your branch up to date:
rebase this branch with main
update my branch with the latest from main
Let Copilot help resolve merge conflicts:
rebase this branch with main and fix any merge conflicts
What Copilot does:
- Performs the rebase
- Identifies conflicts
- Analyzes both versions
- Suggests the correct resolution based on context
- 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();
}
}
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
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
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 platformscreate a PR description focusing on the performance improvements
write a PR description that explains the technical approach in detail
create a new branch called fix/collectionview-crash
switch to branch main
create a branch for issue #12345
delete my local branch after it's been merged
list all my local branches
show me what's changed
what files did I modify?
are there any uncommitted changes?
show me the last 5 commits
who changed this file recently?
when was CollectionViewHandler.cs last modified?
undo my changes to MainPage.xaml
discard all uncommitted changes
revert the last commit but keep the changes
unstage all my changes
remove CollectionView.cs from staging
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 changesInstead of:
help with git
Try:
commit my SafeArea fixes with a message explaining the iOS keyboard issue
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?
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"
Copilot automatically generates commits following the Conventional Commits standard:
<type>(<scope>): <description>
[optional body]
[optional footer]
- 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
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
- 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
- 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
| 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 |
Good branch names help Copilot understand context:
- ✅
fix/collectionview-crash-12345 - ✅
feat/add-selection-support - ❌
stuff - ❌
temp123
Smaller, frequent commits are easier for Copilot to describe accurately than large, monolithic commits.
Stage related changes together:
# Good - related changes together
git add src/Controls/CollectionView/*
# Less ideal - unrelated changes
git add .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.
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?
start an interactive rebase for the last 5 commits
help me clean up my commit history
cherry-pick commit abc123 to this branch
apply the changes from that commit to my current branch
stash my current changes
apply my stashed changes
list all my stashes
move my last commit to a new branch
undo my last commit but keep the changes
explain these merge conflicts and help me resolve them
amend my last commit message