Skip to main content

Git Integration in Visual Studio

Level: Intermediate

ℹ️ What You'll Learn
  • 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 code
  • feature/student-management — Student CRUD
  • feature/fee-module — Fee calculation
  • feature/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-managementMerge '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:

  1. Click "Publish Branch"
  2. Sign in with GitHub
  3. Authorize Visual Studio
  4. 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

ShortcutAction
Ctrl + 0, Ctrl + GOpen Git Changes
Ctrl + Shift + 0Open 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
💡 Git Pro Tip

Commit frequently with clear messages. Makes history readable and debugging easier.

⚠️ Common Git Mistakes
  1. Not pulling before push — Merge conflicts
  2. Large commits — Hard to review
  3. Unclear messages — Confusing history
  4. Merge without testing — Broken main branch
🤖Use AI to Learn Faster

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.

nexcoding.in