Integration of Git into Visual Studio
Nearly all versions of the Visual Studio IDE provide integration features for source control. Git Client is directly built into all the latest versions of Visual Studio IDE. This documentation is about using git in Visual Studio 2019 version.
Git Cloning Process: -
1. All features relevant to Git are available at the ‘Team Explorer’ section. To locate this feature, select from the menu ‘View > Team Explorer’ option that appears as follows in Visual Studio 2019 IDE.
2. To clone a git repository from a remote server by using URL, select the ‘Clone’ option from the ‘Team Explorer’ section and provide the git URL, then click again on the ‘Clone’ option as shown below.
3. After the cloning is done, projects will be appearing in ‘Solution Explorer’ section as shown follows.
Git Operations (Commit, Push, Pull and Fetch): -
1. Using the ‘Team Explorer’ feature, we can commit, push, and pull the changes into a local/remote repository. All the git operations and projects of the git related are available here as shown below.
2. Let's make some changes in 'Program.cs' file (e.g. inserted comment line), as shown below. All the new/modified files appear in ‘Changes’ area then write a meaningful commit message and press the ‘Commit and Push’ button. Also, check the changes reflected in the remote repository page below.
3. Pulling changes made by other project team members. The image below shows changes that are pulled from remote repository. Go to 'Team Explorer' section and Select ‘Sync > Pull’ Option.
Creating and Switching Git Branches: -
1. To create a new branch, from ‘Team Explorer’ section, select ‘Branches > New Branch’ option then give the branch name and press ‘Create Branch’ button.
2. To switch the branches, from ‘Team Explorer’ section, select ‘Branches’ and Right-click on the branch which you want to shift then select ‘Checkout’ option.
Solving Conflicts: -
Whenever two team members of the team change the same file, conflicts may occur. So, we need to fix such conflicts manually.
1. Let’s take an example of ‘Program.cs’ file only. Suppose Person A makes changes and Person B also makes changes to the same file, then there can be conflicts as shown below.
2. After the changes have been manually merged/fixed, save the file to mark the conflicts as resolve and press the ‘Commit Merge’ button to fix the conflict from ‘Team Explorer’.