📜 ⬆️ ⬇️

Git and Visual Studio: how to cook

Some time ago we announced Git support in Visual Studio and TFS. In order to learn how to cook it all, I myself went all the way and I want to tell you about him. Below is about how to use Git in VS.

What do you need:
Sign Up for a Free Visual Studio Online Account
Download and install Visual Studio 2012/2013
Put Visual Studio Tools for Git on the installed studio

Git and TFS: Friendship Story



Git is a distributed version control system, where each developer has a copy of the entire repository, which means excellent support for offline development. Git also has a good, clear model of branching, and the developer doesn’t have to think long about how to create local or private branches for ease of use. In general, everything is fine with Git, and MSDN has a dedicated Git brunch .
')

Git project in Team Foundation Service


After registering with TFS, there is a new button on the command page - New Team Project + Git. A couple of clicks and the Git project is ready.





Actually, that's all. :) But this is the tip of the iceberg, inside the integration is much more difficult. Further - about how to connect from Visual Studio and manipulate our Git-project.

Visual Studio and Git


I immediately make a reservation - Visual Studio is not a replacement for the existing Git UI. Visual Studio can be a substitute, but more often used in conjunction with other means. If Git was created inside TFS, then the developer has some features that come from TFS, for example, Work Items, but VS works quietly with any local repositories and well-deserved Git-figures in the face of GitHub and BitBucket.

To connect to the Git repository, just press TEAM | Connect to Team Foundation Server.



Team Explorer will open. As you can see, I already have a replicated (with GitHub) repository, and right there - the TFS repository. To clone a new Git repository, you can click Clone and enter the connection data.



To connect your Visual Studio Online account, click Select Team Projects, select an account and set which repository you need to pull us to VS.



After connecting the projects, select the desired one and click the Clone button in the context menu.





This completes the cloning process - a cloned repository will appear in the Team Explorer in the Local Git Repositories branch. I repeat - using Clone, you can clone any Git repository.

Another interesting feature of the integration of Visual Studio and Git is the ability to create a new project and immediately add it to the local version control system. To do this, when creating a new project in VS, it suffices to mark Add to source control.





Before you commit something to the repository, you need to set the data for the commit - click on Changes and a warning that you need to enter data.



Useful features on this page are still inside Repository Settings - you can configure .gitIgnore and .gitattributes.
Then you can commit.



Pull


To make a Pull and get the latest updates from the team, you need to go to Commits and press Fetch in order to first see what will come there (and whether there is anything to come).



All is well - click Pull and get the latest update. More information can be found here - Pull changes from the team .

Push


C Push is simple - in the same window Commits click Push. We will get a message that everything is fine. You can read more about Push here - Push your changes .



Using brunch


For the use of brunches in Team Explorer, a special section Branches is highlighted.



After connecting to the repository, only master is available.



Create a new brunch by clicking New Branch.





Since Git branches are local until Push, the new branch will be placed in Unpublished Branches. You can change the brunch for commits on the Commits page mentioned above.



Content can be merged by clicking Merge and selecting branches. Learn more about brits and merdzhi - Git Branching .



If conflicts arise in the process of merge or pool, they can immediately be split (the simplest, of course).



To view the history, simply click View History in the context menu of the branch.



By clicking on the commit we get detailed information about what happened.



Much of this is also available on the TFS portal. In order to go there from VS, on the project page in Team Explorer you need to click Web Portal.



Already on the portal you can explore the general state of the repository ...



... single commits ...



... and detailed information about these commits.





Summary


We briefly looked at how a very simple process of interaction between Visual Studio and Git looks. As mentioned at the outset, the fruit of integrating Git into Visual Studio is not a hint that Visual Studio will completely replace the workflow. But the fact that one of the most popular IDEs has become excellent in supporting one of the most popular version control systems is, in my opinion, a remarkable fact, and will definitely appeal to those who use both.

Source: https://habr.com/ru/post/216037/


All Articles