Enhancing Skills

Merging and Closinga Pull Request (PR) in VS Code & GitHub Desktop

Merging and Closing a Pull Request (PR) in VS Code, GitHub Desktop, or GitHub

🚀 Featured Snippet

To merge and close a pull request, open the PR on GitHub, review the Files changed tab, click the Merge pull request dropdown, choose Squash and merge, confirm the merge, delete the branch, then pull the latest changes locally and delete your local branch.


Overview

When your pull request (PR) is ready, your goal is to merge it cleanly and remove all leftover branches.

Standard workflow:

  • Review the PR
  • Merge it
  • Delete the remote branch
  • Pull latest changes
  • Delete the local branch

✅ Goal

  • One PR = one clean commit
  • No leftover branches
  • Clean, readable history

Merge Options (What Button to Choose)

Squash and Merge (Recommended)

Button label: Squash and merge

  • Found under the green merge button dropdown
  • Combines all commits into one
  • Best for most PRs

✅ Recommended

Use Squash and merge almost every time


Create a Merge Commit

Button label: Create a merge commit

  • Keeps all commits
  • Adds an extra merge commit

⚠️ Use When

You want full commit history preserved


Rebase and Merge

Button label: Rebase and merge

  • No merge commit
  • Linear history

🚫 Caution

Avoid unless you understand rebasing


🖼️ Visual: GitHub Merge Buttons

Image
Image
Image
Image

✅ Key Buttons to Recognize

  • Green Merge pull request button
  • Small dropdown arrow ▼ next to it
  • Squash and merge option
  • Confirm squash and merge button
  • Delete branch button

VS Code Setup for GitHub (First-Time Users)

Step 1: Install Git

Check if installed:

git --version

If not installed:

  • Download from git-scm.com
  • Install with defaults

⚠️ Required

VS Code cannot manage repos without Git


Step 2: Install GitHub Pull Requests Extension

Steps:

  1. Open VS Code
  2. Click Extensions icon (left sidebar, looks like 4 squares)
  3. Search:
    GitHub Pull Requests and Issues
  4. Click Install

🖼️ Visual: VS Code Extensions Panel

Image
Image
Image
Image

Step 3: Sign Into GitHub

  • Look for Sign in to GitHub (bottom-left or popup)
  • Click it
  • Browser opens → click Authorize

⚠️ Important

If you skip this, you will NOT see pull requests


Step 4: Open Your Repository

Option A: Clone repo

Press:
Ctrl + Shift + P

Type:
Git: Clone

Paste your repo URL


Option B: Open existing repo

  • File → Open Folder
  • Select your repo

Step 5: Verify Git is Working

Click:
Source Control icon (branch icon 🌿)

You should see:

  • Changes
  • Branch name

Step 6: Find Pull Requests Panel

🖼️ Visual: VS Code Sidebar + PR Panel

Image
Image
Image
Image

Option A (best):

  • Click GitHub / PR icon in left sidebar

Option B:

  • Click Source Control
  • Look for Pull Requests section

Option C (always works):

Press:
Ctrl + Shift + P

Type:
Pull Requests

Click:
GitHub Pull Requests: Focus on Pull Requests View


🚫 Common Problem

No Pull Requests panel:

Fix:

  • Install GitHub Pull Requests extension
  • Sign into GitHub
  • Open a repo folder

Option 1: VS Code → GitHub (Recommended Flow)

Step 1: Open PR in VS Code

  • Click GitHub / PR icon
  • Click your PR

Step 2: Review Changes

  • Click Files Changed
  • Open each file

🚫 Never Skip

Always review files before merging


Step 3: Click “Open on GitHub”

  • Top-right of PR view
  • Click Open on GitHub

Step 4: Merge PR (on GitHub)

Scroll to bottom:

  • Click Merge pull request ▼
  • Select Squash and merge
  • Click Confirm squash and merge

Step 5: Delete Remote Branch

  • Click Delete branch

Step 6: Update Local Repo

git checkout main
git pull

Step 7: Delete Local Branch

git branch -d your-branch-name

Option 2: GitHub Website (Easiest)

Step 1: Open PR

  • Go to repo
  • Click Pull requests
  • Click your PR

Step 2: Review Changes

  • Click Files changed

✅ Rule

If anything looks wrong → STOP


Step 3: Merge

Scroll down:

  • Click Merge pull request ▼
  • Select Squash and merge
  • Click Confirm squash and merge

Step 4: Delete Branch

  • Click Delete branch

Step 5: Update Local Repo

git checkout main
git pull

Step 6: Delete Local Branch

git branch -d your-branch-name

Option 3: GitHub Desktop

Step 1: Open Repo

  • Open GitHub Desktop

Step 2: Click “View on GitHub”

  • Opens PR in browser

Step 3: Merge

Follow GitHub Website steps above


Recommended Workflow

✅ Always Do This

  1. Open PR
  2. Click Files changed
  3. Review everything
  4. Click Squash and merge
  5. Click Confirm
  6. Click Delete branch
  7. Pull latest main
  8. Delete local branch

Common Mistakes to Avoid

🚫 Avoid These

  • Not reviewing files
  • Using wrong merge option
  • Forgetting to delete branch
  • Not pulling latest main
  • Reusing old branches

💡 Pro Tip

  • One PR = one purpose
  • Squash merge keeps history clean
  • Always delete branches

Summary

After a proper merge:

  • PR shows Merged
  • Remote branch is deleted
  • Local main is updated
  • Local branch is deleted
  • Repo stays clean

✅ End Result

Clean repo, clean history, no leftovers


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.