DEV Community

She11 QA
She11 QA

Posted on

Essential Git Commands for Feature Branch Workflow

How to Switch, Sync, and Merge Git Branches in VS Code

Keeping your feature or QA branch up to date with the main codebase is essential for preventing merge conflicts later down the line. Here is a quick reference guide on how to switch branches, fetch new remotes, and pull the latest changes into your branch using VS Code and Git terminal.


1. How to Switch Branches in VS Code

Using the Command Palette:

  1. Press Ctrl + Shift + P (Windows/Linux) or Cmd + Shift + P (Mac).
  2. Type and select Git: Checkout to...
  3. Select your target branch (e.g., your-feature-branch).

Using the Terminal:

If the branch hasn't been fetched locally yet:

# Fetch the specific branch from remote
git fetch origin your-feature-branch

# Switch to the branch
git checkout your-feature-branch
Enter fullscreen mode Exit fullscreen mode

2. Syncing Your Branch with the Latest Main Code

Follow these 5 steps to update your local working branch with the latest upstream code from main:

Step 1: Switch to the Main Branch

git checkout main
Enter fullscreen mode Exit fullscreen mode

Step 2: Pull Remote Changes

git pull origin main
Enter fullscreen mode Exit fullscreen mode

Step 3: Return to Your Feature Branch

git checkout your-feature-branch
Enter fullscreen mode Exit fullscreen mode

Step 4: Merge Main into Your Branch

git merge main
Enter fullscreen mode Exit fullscreen mode

Handling Conflicts: If VS Code highlights merge conflicts, edit the files to resolve them, then stage and commit:
git add .
git commit -m "Merge main into your-feature-branch"

Step 5: Push Updates to Remote

git push origin your-feature-branch
Enter fullscreen mode Exit fullscreen mode

Quick Summary Checklist

  • git checkout main → Jump to main

  • git pull origin main → Get latest changes

  • git checkout → Return to your working branch

  • git merge main → Bring latest main changes into your branch

  • git push origin → Push updated work to remote

Top comments (0)