168

In Visual Studio Code it seems that I am only allowed to push, pull and sync. There is documented support for merge conflicts but I can't figure out how to actually merge between two branches. The Git command line within VSC (press F1) only facillitates a subset of commands:

eGit options available in VSCode

Attempting to pull from a an alternate branch or push to an alternate branch yields:

git Command throttling

Here's the documentation on VSCode's Git Visual Studio Code Git Documentation

What am I overlooking?

2
  • Are you sure you have checked everywhere, q.v. this blog which discusses how to merge two branches? Commented Jul 29, 2016 at 0:35
  • 7
    That's Visual Studio and not Visual Studio Code which is a separate application altogether. More info: VisualStudio.com and code.visualstudio.com Commented Jul 29, 2016 at 0:37

6 Answers 6

215

You can do it without using plugins.

In the latest version of vscode that I'm using (1.17.0) you can simply open the branch that you want (from the bottom left menu) then press ctrl+shift+p and type Git: Merge branch and then choose the other branch that you want to merge from (to the current one)

Sign up to request clarification or add additional context in comments.

3 Comments

After I select Git: Merge branch branch, will it commit automatically?
@JyotiPrasadPal yes you just need to git: push/sync
2024 update: this option is now called "Git: Merge..."
82

Actually you can do with VS Code the following:

Merge Local Branch with VS Code

3 Comments

For clarity, I'd like to add: FIRST you need to move (checkout) to the branch that you want to bring changes into; this can be done by clicking the branch name in the bottom-left of the Status Bar (it has a little source control branch icon next to it). SECOND: do as depicted in the image (Branch > Merge Branch...). THIRD: in the menu that appears select the branch that you want to take changes from.
Someone should edit the above comment into the answer as it's a pretty important note.
@user1816847 I have added my comment as an answer as requested. This is the current approach as of Version 1.93.0 (8 September 2024).
58

Update June 2017 (from VSCode 1.14)

The ability to merge local branches has been added through PR 25731 and commit 89cd05f: accessible through the "Git: merge branch" command.
And PR 27405 added handling the diff3-style merge correctly.

Vahid's answer mention 1.17, but that September release actually added nothing regarding merge.
Only the 1.18 October one added Git conflict markers

https://code.visualstudio.com/assets/updates/1_18/merge.png

From 1.18, with the combination of merge command (1.14) and merge markers (1.18), you truly can do local merges between branches.


Original answer 2016:

The Version Control doc does not mention merge commands, only merge status and conflict support.

Even the latest 1.3 June release does not bring anything new to the VCS front.

This is supported by issue 5770 which confirms you cannot use VS Code as a git mergetool, because:

Is this feature being included in the next iteration, by any chance?

Probably not, this is a big endeavour, since a merge UI needs to be implemented.

That leaves the actual merge to be initiated from command line only.

8 Comments

Well that sucks!
Good suggestion but it's command line or Git Gui/Extensions for me, but it would be cool to have this built into Visual Studio Code as it is in regular Visual Studio.
Merging branches is day to day task for me. We need support for merging in VSCode.
@JonathanRamos, There are tools for everything, VSCode focuses on your needs to code, you need to look for a Git specific tool if you are a power user. It is possible that MS will introduce this feature in the future but there are other alternatives at the moment.
Would be nice a feature like the one in Visual Studio Community
|
32

I had the same question, so I created Git Merger.
hope this helps :)

Comments

8

I found this extension for VS code called Git Merger. It adds Git: Merge from to the commands.

2 Comments

The guy 2 comments above literally wrote it X)
*person 2 comments above
5

Step-by-step guide to Git repository setup, making changes, and merging branches (see Step 4); moving my previous comment (TLDR) into an answer for completeness.

TLDR

  1. Move (checkout) to the branch that you want to bring changes INTO (click the branch name in the bottom-left of the Status Bar (next to the little source control branch icon).
  2. In the Source Control pane, click the 3 dots menu > Branch > Merge...
  3. In the Command Palette menu that appears, select the branch that you want to take changes FROM.

This is detailed in Step 4.

Visual Studio Code (vscode)

Step 1 (Initialise/Clone)

In Visual Studio Code, if a repository (repo) has not already been created you can either Initialise a local repo or Clone from a remote repo:

A. Initialise Local

  1. Go to Source Control pane.
  2. For a new local repo, click Initialise Repository.
    1. To publish to a remote directly instead (which will also initialise the local), select Publish to GitHub:
    2. In the Command Palette dropdown menu that appears, select to publish to private or public remote. Initialise, publish local repo
  3. Enter a commit message.
  4. Stage changes (remember to Save files also):
    1. For individual files: Hover mouse over each file and select +.
    2. For all files: Hover mouse over Changes heading and select +.
  5. Click Commit button.
    1. Repeat steps 3, 4, 5 for subsequent commits. Stage commits
  6. To push to a remote, click Publish Branch (if not already associated with a remote):
    1. In the Command Palette dropdown menu that appears, select to publish to private or public remote. Publish to remote
  7. If associated with a remote, select the dropdown on the Commit button to Commit & Sync to perform this all in one action. Commit and Sync

B. Clone Remote

  1. Copy remote repo URL from internet browser.
  2. In vscode (not in a project folder with a Git repo, i.e. a new session window), go to Source Control pane.
  3. Select Clone Repoository button.
  4. In the Command Palette dropdown menu that appears, paste the remote URL. Clone remote repo

Step 2 (Make Changes)

Make changes and commit according to Step 1, A. 3, 4, 5, 7.

Step 3 (Branch Actions)

  1. In vscode, in the Status Bar at the bottom of the window, next to the Source Control icon there is the name of the current selected branch, click it. Status Bar branch
  2. In the Command Palette dropdown menu that appears, select Create new branch... Command Palette branch actions
  3. To checkout (move) to a branch:
    1. Click the Source Control branch in the Status Bar (Step 3, 1).
    2. Select the branch to checkout to.
    3. Typically, moving is between local branches which are then synchronised with the remote; or moving to a remote branch in which commits are then fetched to the local.

Alternatively, in the the Source Control pane, click the 3 dots (...) menu of the Source Control heading and navigate to the option.

Step 4 (Merging Branches)

  1. Checkout (move) to the branch that you want to bring changes INTO (Step 3, 3). Checkout to branch to bring changes into
  2. On the Source Control pane:
    1. Click the 3 dots (...) menu.
    2. Branch > Merge... Source Control pane to 3 dots menu to Branch to Merge
  3. In the Command Palette dropdown menu that appears, select the branch that you want to take changes FROM. Command Palette select branch to take changes from
  4. To synchronise changes with the remote click the Sync Changes button on the Source Control pane. Sync with remote after merge

For more info check out: VS Code overview

1 Comment

For me the 3 dots appear per git repo

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.