GitHub in Visual Studio 2022 IDE
Using GitHub in Visual Studio 2022 for a team project:
Team Lead (creates project, manages branches, reviews PRs)
Developers (Receptionist, Doctor, Pharmacy, Lab Test modules)
Administrator
Tester
1. Prerequisites
Install Visual Studio 2022 (any edition with Git support)
Install Git for Windows (if not already installed)
Create a GitHub account
Install GitHub Extension for Visual Studio (already integrated in VS 2022)
2. Team Lead: Create Remote Repository on GitHub
Log in to GitHub → Click + → New repository
Repository name:
EmployeeManagementSystemDescription:
EMS for clinic/hospitalChoose Private (for team)
Do NOT initialize with README (we'll push from VS)
Click Create repository
3. Team Lead: Create Local Project & Push to GitHub
Open Visual Studio 2022 → Create a new project
Choose ASP.NET Core Web App (MVC) or Console App (based on your stack)
Project name:
EmployeeManagementSystemLocation:
C:\EMS\Check Place solution and project in same directory
Click Create
After project loads: Git → Create Git Repository (bottom right)
Or: View → Git Changes → Create Git RepositoryIn dialog:
Check Push to GitHub
GitHub account → Sign in
Repository name:
EmployeeManagementSystemChoose Private
Click Create and Push
✅ Done: Remote and local repositories linked.
4. Team Lead: Add Collaborators
Go to GitHub repo → Settings → Collaborators
Click Add people
Add team members’ GitHub usernames/emails:
Developer 1 (Receptionist)
Developer 2 (Doctor)
Developer 3 (Pharmacy)
Developer 4 (Lab Test)
Developer 5 (Admin)
Tester
Each member accepts invite via email/GitHub notification.
5. Each Team Member: Clone Repository Locally
For each developer & tester:
Open Visual Studio 2022
Clone a repository (from start window)
Or: Git → Clone RepositoryRepository URL:
https://github.com/your-team/EmployeeManagementSystem.gitLocal path:
C:\EMS\Clone\(each member uses own folder)Click Clone
✅ Now each member has a local copy of the main branch.
6. Team Lead: Create Branches for Each Module
In Visual Studio (Team Lead only):
Open Git Changes (Ctrl + Shift + G)
Click Branches (drop-down in top bar) → New Branch
Create branches:
feature/receptionist-modulefeature/doctor-modulefeature/pharmacy-modulefeature/labtest-modulefeature/admin-moduletesting/main(for tester)
Push each branch to remote:
Git→Pushafter creating each branch.
7. Each Developer: Switch to Their Branch & Work
Example: Receptionist Module Developer
Open project in VS 2022
Git Changes → Branches → Select
feature/receptionist-moduleStart coding (e.g., add
ReceptionistController.cs, views, models)Commit:
Right-click on changed file → Stage (or stage all)
Commit message:
Add appointment booking UIClick Commit Staged
Push to remote:
Git Changes → Push (up arrow)
Or
Ctrl + Shift + G→ Push
Repeat for other modules similarly.
8. Daily Sync: Pull & Fetch
Each team member (start of day):
Git Changes → Branches → Ensure you’re on your branch
Fetch (globe icon) → This checks for remote changes without merging.
Pull (down arrow) → Pulls latest changes from remote branch to local.
Pull without opening VS:
Git→Pulldirectly from menu.
9. Tester: Pull & Test Feature Branches
Tester switches to each branch:
Git Branches → Checkout
feature/receptionist-modulePull latest
Run app → Test functionality
Report bugs back to developer (non-Git, via issue tracker)
10. Developer: Create Pull Request (PR) to Merge into Main
Example: Receptionist module ready to merge
From GitHub website (easier for PRs) or VS:
From VS 2022:
Git Changes → Branches → Right-click
feature/receptionist-moduleCreate Pull Request
Base:
main← Compare:feature/receptionist-moduleAdd description:
Completed receptionist moduleAssign Team Lead as reviewer
Click Create
From GitHub:
Go to repo → Pull requests → New pull request → same as above.
11. Team Lead: Review & Merge Pull Request
GitHub → Pull requests → Open PR
Check Files changed tab
Add comments if needed
If OK, click Merge pull request → Confirm merge
Delete the feature branch (optional but recommended)
After merge, the main branch has the new code.
12. All Members: Sync Updated Main Locally
After any merge into main:
Switch to
mainbranch in VS:
Git Changes → Branches → CheckoutmainPull latest changes
For developers working on ongoing feature branches, they should also update from main:
Rebase/merge main into feature branch:
Checkout
feature/doctor-moduleOpen Git Changes → Branches → Right-click
main→ Merge into current branch
Or Rebase (cleaner).Resolve any conflicts (see next step).
13. Resolving Merge Conflicts
Scenario: Two developers change same file (e.g., Startup.cs)
How conflict occurs:
Developer A (Receptionist) commits line 20
Developer B (Doctor) commits line 20 to same file
Both push → second push gets rejected.
Resolution steps in VS 2022:
Git Changes shows:
Conflicts detectedClick Conflicts link
Open conflicting file (red icon)
VS 2022 opens Merge Editor:
Incoming (remote change)
Current (local change)
Result pane – choose which to keep or edit manually.
After fixing → Click Accept Merge
Commit (VS auto-stages resolution)
Push
14. Additional Scenarios
A. Undo local changes before commit:
Git Changes → Right-click file → Undo Changes
B. Revert a commit already pushed:
Git → View Branch History → Right-click commit → Revert → Push.
C. Stash changes (switch branch without committing):
Git Changes → Stash → Pop later.
D. Tag a release (Team Lead):
Git → Create Tag →
v1.0→ Push tag to remote.
15. Recommended .gitignore (for C# projects)
Ensure Visual Studio automatically adds .gitignore for:
bin/obj/*.user*.suopackages/
If missing, add from VS: Git → Settings → Git Repository Settings → Add default ignore.
16. Branch Strategy Summary for Your Team
| Role | Branch to work on |
|---|---|
| Team Lead | main, creates branches |
| Receptionist Dev | feature/receptionist-module |
| Doctor Dev | feature/doctor-module |
| Pharmacy Dev | feature/pharmacy-module |
| Lab Test Dev | feature/labtest-module |
| Admin Dev | feature/admin-module |
| Tester | testing/main (or checks out feature branches) |
PR target branch:
mainTester merges: No; tester only pulls, reviews, tests, reports.
17. Common Visual Studio 2022 Git Shortcuts
| Action | Shortcut |
|---|---|
| Git Changes | Ctrl + Shift + G |
| Git Repository window | Ctrl + G, Ctrl + R |
| Commit | Ctrl + Enter (in Git Changes) |
| Sync (Fetch + Pull) | Ctrl + Shift + S |
| View Branches | Ctrl + G, B |
18. Troubleshooting
| Issue | Solution |
|---|---|
| Authentication fail | VS → Git Settings → Re-authenticate to GitHub |
| Cannot push to main | Branch protection rule? Team Lead must allow PR merges |
| Merge conflict on same file | Use VS Merge Editor (step 13) |
| Forgot to pull before commit | Fetch → Rebase or Merge |
Comments
Post a Comment