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

  1. Log in to GitHub → Click + → New repository

  2. Repository name: EmployeeManagementSystem

  3. Description: EMS for clinic/hospital

  4. Choose Private (for team)

  5. Do NOT initialize with README (we'll push from VS)

  6. Click Create repository


3. Team Lead: Create Local Project & Push to GitHub

  1. Open Visual Studio 2022 → Create a new project

  2. Choose ASP.NET Core Web App (MVC) or Console App (based on your stack)

  3. Project name: EmployeeManagementSystem

  4. Location: C:\EMS\

  5. Check Place solution and project in same directory

  6. Click Create

  7. After project loads: Git → Create Git Repository (bottom right)
    Or: View → Git Changes → Create Git Repository

  8. In dialog:

    • Check Push to GitHub

    • GitHub account → Sign in

    • Repository name: EmployeeManagementSystem

    • Choose Private

    • Click Create and Push

✅ Done: Remote and local repositories linked.


4. Team Lead: Add Collaborators

  1. Go to GitHub repo → Settings → Collaborators

  2. Click Add people

  3. Add team members’ GitHub usernames/emails:

    • Developer 1 (Receptionist)

    • Developer 2 (Doctor)

    • Developer 3 (Pharmacy)

    • Developer 4 (Lab Test)

    • Developer 5 (Admin)

    • Tester

  4. Each member accepts invite via email/GitHub notification.


5. Each Team Member: Clone Repository Locally

For each developer & tester:

  1. Open Visual Studio 2022

  2. Clone a repository (from start window)
    Or: Git → Clone Repository

  3. Repository URL: https://github.com/your-team/EmployeeManagementSystem.git

  4. Local path: C:\EMS\Clone\ (each member uses own folder)

  5. 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):

  1. Open Git Changes (Ctrl + Shift + G)

  2. Click Branches (drop-down in top bar) → New Branch

  3. Create branches:

    • feature/receptionist-module

    • feature/doctor-module

    • feature/pharmacy-module

    • feature/labtest-module

    • feature/admin-module

    • testing/main (for tester)

  4. Push each branch to remote:
    Git → Push after creating each branch.


7. Each Developer: Switch to Their Branch & Work

Example: Receptionist Module Developer

  1. Open project in VS 2022

  2. Git Changes → Branches → Select feature/receptionist-module

  3. Start coding (e.g., add ReceptionistController.cs, views, models)

  4. Commit:

    • Right-click on changed file → Stage (or stage all)

    • Commit message: Add appointment booking UI

    • Click Commit Staged

  5. 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):

  1. Git Changes → Branches → Ensure you’re on your branch

  2. Fetch (globe icon) → This checks for remote changes without merging.

  3. Pull (down arrow) → Pulls latest changes from remote branch to local.

Pull without opening VS:

  • Git → Pull directly from menu.


9. Tester: Pull & Test Feature Branches

Tester switches to each branch:

  1. Git Branches → Checkout feature/receptionist-module

  2. Pull latest

  3. Run app → Test functionality

  4. 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:

  1. Git Changes → Branches → Right-click feature/receptionist-module

  2. Create Pull Request

  3. Base: main ← Compare: feature/receptionist-module

  4. Add description: Completed receptionist module

  5. Assign Team Lead as reviewer

  6. Click Create

From GitHub:

  • Go to repo → Pull requests → New pull request → same as above.


11. Team Lead: Review & Merge Pull Request

  1. GitHub → Pull requests → Open PR

  2. Check Files changed tab

  3. Add comments if needed

  4. If OK, click Merge pull request → Confirm merge

  5. 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:

  1. Switch to main branch in VS:
    Git Changes → Branches → Checkout main

  2. Pull latest changes

For developers working on ongoing feature branches, they should also update from main:

Rebase/merge main into feature branch:

  1. Checkout feature/doctor-module

  2. Open Git Changes → Branches → Right-click main → Merge into current branch
    Or Rebase (cleaner).

  3. 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:

  1. Git Changes shows: Conflicts detected

  2. Click Conflicts link

  3. Open conflicting file (red icon)

  4. VS 2022 opens Merge Editor:

    • Incoming (remote change)

    • Current (local change)

    • Result pane – choose which to keep or edit manually.

  5. After fixing → Click Accept Merge

  6. Commit (VS auto-stages resolution)

  7. 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

  • *.suo

  • packages/

If missing, add from VS: Git → Settings → Git Repository Settings → Add default ignore.


16. Branch Strategy Summary for Your Team

RoleBranch to work on
Team Leadmain, creates branches
Receptionist Devfeature/receptionist-module
Doctor Devfeature/doctor-module
Pharmacy Devfeature/pharmacy-module
Lab Test Devfeature/labtest-module
Admin Devfeature/admin-module
Testertesting/main (or checks out feature branches)
  • PR target branch: main

  • Tester merges: No; tester only pulls, reviews, tests, reports.


17. Common Visual Studio 2022 Git Shortcuts

ActionShortcut
Git ChangesCtrl + Shift + G
Git Repository windowCtrl + G, Ctrl + R
CommitCtrl + Enter (in Git Changes)
Sync (Fetch + Pull)Ctrl + Shift + S
View BranchesCtrl + G, B

18. Troubleshooting

IssueSolution
Authentication failVS → Git Settings → Re-authenticate to GitHub
Cannot push to mainBranch protection rule? Team Lead must allow PR merges
Merge conflict on same fileUse VS Merge Editor (step 13)
Forgot to pull before commitFetch → Rebase or Merge

Comments

Popular posts from this blog

Interview Tips: Dot NET Framework vs Net CORE

OOP Concept in real-time scenario: Mobile Device Management Software

ORACLE 11g: User Authentication System with Stored Procedure and SQL*Plus Integration