Git: How to merge feature branch into master using VS Code source control?
STARTING VS Code 1.48, many of the Git commands are now available as menu options from the Source Control panel, including merging of branches. See the "New Git View submenus" section of the July 2020 (1.48) release notes:
Thanks to the new submenu proposed API, the Git View and More Actions (...) menu has been refactored for better organization of several commands:
To merge branches (ex. merge featureA into master):
- Select the destination branch (ex. master)
- Select the branch to be merged (ex. featureA)
- Push the updated branch (ex. master)
BEFORE VS Code 1.48, VS Code Source Control has no UI for merging branches. But you can do the merge with commands from the Command Palette.
To merge branches (ex. merge my-feature-branch into master):
-
Checkout the destination branch (master)
-
Make sure master is synchronized with the remote
-
Merge the feature branch
-
Confirm the merge
While using the VS Code Source Control UI can work, I highly recommend learning how to use Git from the command line, as those can be simpler to use, yet they give you more control over Git operations. Plus, they work even outside VS Code, as long as you have access to a terminal.
As an example, the same branch merging operation can be performed from a terminal.
$ git checkout master
$ git pull
$ git merge my-feature-branch
$ git log
commit 54971a1cc845459742392061e71ef4fcb2444357 (HEAD -> master)
Merge: e8fad11 b1d9050
Author: XXX
Date: Wed May 13 20:14:15 2020 +0900
Merge branch 'my-feature-branch'
...
The best place to learn about Git is here: https://git-scm.com/book/en/v2.
For specific to git merge
:
- 3.2 Git Branching - Basic Branching and Merging
- What is the best (and safest) way to merge a Git branch into master?
Deepika vijay
Updated on July 25, 2022Comments
-
Deepika vijay almost 2 years
I have created a feature branch in Git using Visual Studio source control.
Now I want to merge the feature branch into master using Visual Studio Code.
What is the correct process to do this?
-
cryanbhu about 3 yearsmerging seems like one thing where the command line is actually simpler.. commits and pushing, I like to do it in VS Code
-
nhe about 2 yearsThis has now been made easier (I'm not sure as of which version). To merge featureA into main: 1. Switch to main (in Source Control, under Branches, right click main -> Switch To Branch) 2. Right click on featureA, and choose "Merge Branch into Current Branch..." 3. Choose Merge (or Merge and Squash, or whatever option you'd like) 2.