Git Integration in Visual Studio
Level: Intermediate
- Initialize repository
- Commit changes
- Create and switch branches
- Merge branches
- Push to GitHub
- Resolve conflicts
Initialize Git Repository
File → Source Control → Git:
SMS/
├── .git/ (created automatically)
├── .gitignore
├── SMS.sln
└── SMS.Core/
Or from terminal:
cd C:\NexCoding\SMS
git init
Commit Changes
View → Git Changes (or Ctrl + 0, Ctrl + G):
CHANGES
├── Modified: StudentService.cs
├── Modified: Program.cs
├── Untracked: StudentTests.cs
STAGED CHANGES
(drag files here to stage)
Stage files → Type message → Commit All:
Add StudentService CRUD methods
- Implement GetStudent(id)
- Implement CreateStudent(student)
- Implement UpdateStudent(id, student)
- Implement DeleteStudent(id)
Create Branch
Git Changes → Branches → New Branch:
Branch name: feature/fee-management
Based on: main
Creates and switches to new branch
Or terminal:
git checkout -b feature/fee-management
Parallel development on SMS features:
main— Production codefeature/student-management— Student CRUDfeature/fee-module— Fee calculationfeature/exam-module— Exam management
Switch Branch
Git Changes → Branches → Click branch:
Switched to branch 'feature/fee-management'
Current working directory updates.
Merge Branch
Completed feature fee-management. Merge to main:
Git Changes → Branches → Right-click main → Checkout
Right-click fee-management → Merge 'fee-management' into main
Conflicts?
│
├─ No → Merge complete
│
└─ Yes → Resolve conflicts in editor
Git Changes shows conflicted files
Edit markers: <<<< ==== >>>>
Choose: Accept Current / Accept Incoming / Both
Push to GitHub
Git Changes → Branches → Publish Branch:
First time: Connect GitHub account:
- Click "Publish Branch"
- Sign in with GitHub
- Authorize Visual Studio
- Select repository
Subsequent pushes: Git Changes → ⬆ arrow → Push to 'origin'
Files uploaded to GitHub.
Sync Changes
Team updates repo. Pull latest:
Git Changes → ⬇ arrow → Fetch then Pull:
main branch updated locally
View History
Git Changes → Branches → Right-click branch → View History:
Commits:
├── 696027e - Add FeeCalculation service
├── b53bb8d - Fix student list filtering
└── 11012bf - Add exam results
Click commit to see changes.
Key Shortcuts
| Shortcut | Action |
|---|---|
Ctrl + 0, Ctrl + G | Open Git Changes |
Ctrl + Shift + 0 | Open Solution Explorer |
SMS Git Workflow
1. Create branch: feature/exam-management
2. Add Exam model
3. Add ExamService
4. Commit: "Add exam CRUD operations"
5. Push to GitHub
6. Create Pull Request
7. Code review
8. Merge to main
9. Deploy
Collaborative development.
Key Takeaways
- Git = version control in VS
- Commit = save checkpoint
- Branch = parallel development
- Merge = combine branches
- Push = upload to GitHub
- Sync = download team changes
Commit frequently with clear messages. Makes history readable and debugging easier.
- Not pulling before push — Merge conflicts
- Large commits — Hard to review
- Unclear messages — Confusing history
- Merge without testing — Broken main branch
Use ChatGPT, Claude, or Copilot to go deeper on VS Git Integration. Try these prompts:
"How do I create a new branch?""How do I resolve merge conflicts?""When should I commit changes?""Quiz me on Git"
💡 Tip: After reading this article, paste your own code into AI and ask "What could go wrong here and why?" — fastest way to find edge cases and deepen understanding.