Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to merge feature branch into master using VS Code source control?

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?

like image 581
Deepika vijay Avatar asked May 12 '20 15:05

Deepika vijay


1 Answers

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:

enter image description here

To merge branches (ex. merge featureA into master):

  1. Select the destination branch (ex. master)
    • Select ... > Checkout to... enter image description here
    • Select the branch enter image description here
  2. Select the branch to be merged (ex. featureA)
    • Select ... > Branch > Merge Branch... enter image description here
    • Select the branch enter image description here
  3. Push the updated branch (ex. master)
    • Select ... > Pull,Push > Push enter image description here

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

  1. Checkout the destination branch (master)

    • Command Palette > Git: Checkout to...

    • Select the branch

      enter image description here

  2. Make sure master is synchronized with the remote

    enter image description here

  3. Merge the feature branch

    • Command Palette > Git: Merge Branch..

    • Select the branch

      enter image description here

  4. Confirm the merge

    • If the merge completed without conflicts, you should now see from the Source Control UI or from the status bar that you now have new commits that need to be pushed to the remote. (The merge operation was only executed in your local copy of the repo).

      enter image description here


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?
like image 187
Gino Mempin Avatar answered Sep 18 '22 16:09

Gino Mempin