Merging a Pull Request in Visual Studio

November 21, 2014, (updated on January 12, 2015), Software Development

Recently I tried to merge a Pull Request from CodePlex directly in Visual Studio. However, if the Pull Request comes from a forked repository, there is no way around using the command line tools to pull the remote branch into a local branch. It is actually very simple; just perform the following steps.

Pull the changes

Note: If the Pull Request’s branch is in the same repository, you can simply press on New Branch… in Visual Studio and select the appropriate branch in the drop down list. In this case you don’t need to do the next three steps.

  1. In the Team Explorer‘s Branches view, select Actions / Open Command Prompt: This action opens a command prompt whose current directory is set to the root of your local Git repository.

    Image01

  2. In the command prompt, create a new local temporary branch and switch to it.

    git checkout -b TemporaryBranch
    
  3. Next, pull the remote branch from the fork into the temporary branch. The first parameter of the pull command is the remote repository URL, the second parameter is the name of the remote branch to pull into your temporary branch.

    git pull https://git01.codeplex.com/forks/rsuter/visualjsoneditorimprovement master
    

Test the changes

After the previous steps, you should automatically see the new, unpublished branch “TemporaryBranch” in Visual Studio:

Image02

Now test the application with the changes from the Pull Request…

Push the changes

When everything is fine, you can merge the branch back into the “master” branch:

  1. Right-click the “TemporaryBranch” branch and select Merge…

    Image03

  2. Select the “TemporaryBranch” branch on the left and the “master” branch on the right.

    Image04

  3. After pressing the “Merge” button, the changes are merged into the “master” branch and Visual Studio switches back to the “master” branch. Check if the merge worked without issues (e.g. compile and run unit tests).

  4. Press the “Sync” button to push the “Unsynced Commits” back to the main repository server.

    Image05

  5. Now you can delete the “TemporaryBranch” branch directly in Visual Studio:

    Image06

Note: Of course, this also works if you want to merge a Pull Request into a branch different then the “master” branch…

Do you have some suggestions about how to improve this workflow?

Tweet about this on TwitterShare on FacebookEmail this to someoneShare on TumblrShare on LinkedIn

Tags: , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax