Visual Studio For Mac Git Merge

The following example uses a GitHub host, but you can use any Git host for version control in Visual Studio for Mac. If you wish to use GitHub, make sure that you have an account created and configured before following the steps in this article. Visual Studio Code has integrated source control and includes Git support in-the-box. Many other source control providers are available through extensions on the VS Code Marketplace. Tip: Click on an extension tile to read the description and reviews in the Marketplace.

If you are using Visual Studio plugin for Git, but you have also configured Git with MSys git, probably you could be surprised by some Visual Studio behavior. The most obvious one is that commits are done using the wrong user.name and user.email configuration as I’ve described in Visual Studio Tools for Git, a primer, other one can be: tools used to do merge and diff during conflicts.

Suppose you are working with Visual Studio, you issue a pull and find that there is some conflicts in repository.

Figure 1: Pull operation has a conflict

Now you should resolve all conflicts before being able to continue work: you can click on file name that is conflicting and you are presented with a UI different from the one you are used with standard TFS Source control.

Visual studio for mac git merge conflict

Figure 2: Ui to manage conflicts when you are using Git in Visual Studio

If you press “compare files” to visualize diff of files, it could happen that kdiff3 is opened to visualize the difference, instead of resolving directly inside Visual Studio.

Figure 3: File compare is done with Kdiff3 instead of visualizing them inside Visual Studio

This happens because Visual Studio Git Plugin uses standard git configuration, your local repository probably does not have any specific tools for diff and merge (unless you configured them), so global settings are honored. To verify actual settings you can open a Git Bash on the repository, issue a git config –list command and look at merge.tool and diff.tool settings

Figure 4: Actual configuration for merge and diff tools

Since I’ve configured kdiff3 as standard conflict resolution tool after I installed msysgit, Visual Studio honors this settings and opens kdiff3 to do the diff, even if I’m inside the IDE of VS. If you prefer using Visual Studio you should configure VS as diff and merge tools and you can choose to configure this at repository level or at global level. To change only a local repository, open .git folder and edit config file adding this piece of configuration.

Edit: Due to a strange problem with my blog that alters the content of the configuration,

The exact configuration to use visual studio 2013 is found into this gist: https://gist.github.com/alkampfergit/fca40445f118095e37f549f7058e71cd

The exact configuration to use visual studio 2017 is found into this gist: https://gist.github.com/alkampfergit/46883dcef9fb4bee39a56ce0e69dcf24

If you want to change global configuration, you should edit a file named .gitconfig usually located inside your profile folder (c:usersyourname).

You can edit config file with a standard notepad or text editor, it is a simple text configuration file. Once saved, return to Visual Studio and choose again to compare files, you should now being able to resolve conflicts directly from Visual Studio. If you like this option you can setup Visual Studio as diff and merge tool in global git configuration, so it will be available for every repository you are working with.

Figure 5: Once configured, Visual Studio is used as a diff tool for Git repository

You can use Visual Studio not only for diff, but also for merge; press Merge button and you will be prompted with a merge UI.

Visual studio for mac os x

Figure 6: Merge tool of Visual Studio

Visual Studio For Mac Git Merge Master

Once a file is merged, you can Press the “accept Merge” button in the top left area to resolve conflict and once all conflicts are resolved, you can go to commit pane and commit locally result of merge operations, and everything is done from inside Visual Studio.

Visual Studio For Mac

Gian Maria.

.Net programmer, User group and community enthusiast, programmer - aspiring architect - and guitar player :). Visual Studio ALM MVP View all posts by Ricci Gian Maria
GDPR
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.
titledescriptionauthorms.authorms.datems.assetidms.custom
Using Git in Visual Studio for Mac.
jomatthi
852B6A9D-AEFA-4EF4-A5DD-94A506019D20

Git is a distributed version control system that allows teams to work on the same documents simultaneously. This means that there is a central server that contains all the files, but when a repository is checked out from this central source, the entire repository is cloned to the local machine.

Visual Studio For Mac Git Merge No-ff

The sections below will explore how Git can be used for version control in Visual Studio for Mac.

Git version control menu

The image below illustrates the options provided by Visual Studio for Mac by the Version Control menu item:

Push and Pull

Pushing and Pulling are two of the most commonly used actions within Git. To synchronize changes that other people have made to the remote repository, you must Pull from there. This is done in Visual Studio for Mac by selecting Version Control > Update Solution.

Visual Studio For Mac Git Merge

Once you have updated your files, reviewed and committed them, you must then Push them to the remote repository to allow others to access your changes. This is done in Visual Studio for Mac by selecting Version Control > Push Changes. This will display the Push dialog, allowing you to view the committed changes, and select the branch to push to:

You can also Commit and Push your changes at the same time, via the Commit dialog:

Blame, Log, and Merge

At the bottom of the window, there are five tabs displayed, as illustrated below:

These allow the following actions:

  • Source - Displays your source code file.

  • Changes - Displays the change in code between your local file and the base file. You can also compare different versions of the file from different hashes:

  • Blame - Displays the username of the user associated with each section of code.

  • Log - Displays all the commits, times, dates, messages, and users that are responsible for the file:

  • Merge - This can be used if you have a merge conflict when committing your work. It shows a visual representation of the changes made by you and the other developer, allowing you to combine both sections of code cleanly.

Switching branches

By default, the first branch created in a repository is known as the Master branch. There isn't technically anything different between the master branch and any other, but the master branch is the one that is most often thought of in development teams as the 'live' or 'production' branch.

An independent line of development can be created by branching off Master (or any other branch, for that matter). This provides a new version of the master branch at a point in time, allowing for development independently of what is 'live.' Using branches in this way is often used for features in software development

Users can create as many branches as they like for each repository, but it is recommended that once they have finished using a branch, it is deleted it to keep the repository organized.

Visual Studio Git Hung Merging Changes

Branches are viewed in Visual Studio for Mac by browsing to Version Control > Manage Branches and Remotes...:

Switch to another branch by selecting it in the list and pressing the Switch to Branch button.

To create a new branch select the New button in the Git repository configuration dialog. Enter the new branch name:

You can also set a remote branch to your tracking branch. Read more about tracking branches in the Git documentation.

See the current branch in the Solution Pad, next to the project name:

Reviewing and committing

To review changes in the files, use the Changes, Blame, Log, and Merge tabs on each document, illustrated earlier in this topic.

Review all changes in your project by browsing to the Version Control > Review Solution and Commit menu item:

This allows viewing of all the changes in each file of a project with the option to Revert, Create a Patch, or Commit.

To commit a file to the remote repository, press Commit, enter a commit message, and confirm with the Commit Button:

Once you have committed your changes, push them to the remote repository to allow other users to see them.

Related Video

[!Video https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Visual-Studio-for-Mac-Manage-Projects-with-Git/player]

Visual Studio For Mac Git Merge Conflict

See also