DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Git Operations With Visual Studio, Part 2

Git Operations With Visual Studio, Part 2

In the continuation of this series, we look at how you can merge and fetch using Git commands in Visual Studio.

Arvind Singh Baghel user avatar by
Arvind Singh Baghel
·
Apr. 01, 19 · Tutorial
Like (3)
Save
Tweet
Share
68.78K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

Today, I will show some more advanced Git operations using Visual Studio, without using the Git command line tool. This is the second part of the "Git Operation With Visual Studio" series. Please read the first article here. In the previous article, we have seen Git basic operations like creating repository and branch, cloning, commit, push changes, and more. Now, in this article, I will explain how to merge the branches and resolve the conflicts if any.

Update Local Branch

Update the local repository/branch to get changes from other members who have already made changes and merged. To update the code to keep it synced with others, there are three operations that come into the picture.

  • Fetch: Fetch is used to get the changes from the remote repository but it does not merge them in your code.
  • Merge: Merge is used to apply changes taken from Fetch to a branch in the local repository.
  • Pull: Pull is the combination of two operations — Fetch and then Merge.

We can get the changes to the local branch from the remote server using Fetch. Fetch downloads all the commits and new branches from the remote repository which others have pushed but you do not have. It also creates local branches if needed, but will not merge any changes into the local branches. Fetch only downloads the new commits.

Fetch: Download the Changes

To fetch the changes, go to Team Explorer and click on "Home," then click "Sync."


When you click "Sync," the window is changed to a new View. Now, click on "Fetch" to update the incoming commit list.


When you click on Fetch, you will see the incoming commits list.

Merge: Update Branches

We have downloaded the changes using the Fetch operation. Now, let us merge these changes into the local branch. When we do Sync or Pull from the Changes view, it will perform a merger.

To merge the downloaded changes into your branch, go to Team Explorer and click on "Home." Then, click on "Sync."

We will get a confirmation message.

Merge Branches

Go to Team Explorer and click on "Branches." It will change the view.

Click on "Merge" and you will have to indicate:

  • The branch you want to merge from
  • If you want to commit changes after merging, it will merge on your current branch.

Two things to note: You should always Sync your target branch (master) before merging. You must have the latest version of the branch to avoid another merge. Also, remember your merged branch is only local until you push modifications.

Resolve Conflicts

When modifications on the several branches are contradictory, you will face some conflicts while merging. Git is super smart to understand the merges and changes. It resolves the conflicts by reading the history in your repository to determine the final version for the file, but when it is not clear to the Git, then how do you merge changes? Well, Git stops for those changes and shows the conflicts.

Just click on the "Conflicts" menu.


It will display the list of files with conflicts. Click on each file, and then click on "Merge."


To help you resolve the conflict, Visual Studio will open the conflict resolving tool.

The tool will contain:

  • The file content of the branch you want to merge From (Source)
  • The file content of the branch you want to merge To (Target)
  • The result of the merger


Click on the check-boxes, either source file, target file or both, depending on which you want to keep. Check other conflicts also to click on Next/Previous Conflict to navigate amongst conflicts of the files.

Finally, click on "Accept merge."

When you are done with all the files and don't have conflicts anymore, you can click on "Commit merge," and then, stage your changes and commit as a regular commit.

Conclusion

In this article, we have seen Git operations which we can perform with Visual Studio. I have shown Fetch and Merge operations and the process of merging to different branches. Also, we saw how to resolve conflicts after a merge.

Git Branch (computer science) Fetch (FTP client) Commit (data management)

Published at DZone with permission of Arvind Singh Baghel, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Secure APIs: Best Practices and Measures
  • Building a Real-Time App With Spring Boot, Cassandra, Pulsar, React, and Hilla
  • DevOps vs Agile: Which Approach Will Win the Battle for Efficiency?
  • OWASP Kubernetes Top 10

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: