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?
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):
...
> Checkout to...
...
> Branch
> Merge Branch...
...
> Pull,Push
> Push
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)
Command Palette > Git: Checkout to...
Select the branch
Make sure master is synchronized with the remote
Merge the feature branch
Command Palette > Git: Merge Branch..
Select the branch
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).
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
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With