Simple Setup of Git in Visual Studio Online
When I first started playing with Visual Studio Online, it took a few tries to get the order of operations down to set up a new project and Git repository. This blog post is a reference for the best way to set up a clean repository that’s ready for collaboration.
1. Create the Project
- Open visualstudioonline in a browser, log in or create an account
- From the dashboard, click “New” to create a new project
- Make sure to select Git for source control
2. Connect to the Project from Visual Studio
- Open the “Team Explorer” panel (by default on the right side of the IDE, a tab next to “Solution Explorer”)
- If you are logged in to Visual Studio 2013, it may ask you to re-authenticate
- Click the “Plug” icon to get to the “Connect” view, then click “Select Team Projects…”
- Click the checkbox for your new project, then click "Connect"
- Double-click the new project name in the Team Explorer to select it
3. Clone the Repository
- You are now shown the "Home" panel of Team Explorer. Click "Clone Repository" to create the local clone of the blank repository
- Change the local source code location if you wish, then click "Clone"
4. Add the Default .gitignore
- Click "Settings", then "Git Settings"
- Under "Repository Settings", click the "Add" link for the Ignore File section. This creates the default .gitignore file.
5. (Optional) - Exclude NuGet Packages from Source Control using .gitignore
The default .gitignore does not exclude the packages folder, which would result in everyone checking in their downloaded NuGet packages. There is an entry in the file to exclude them, but it is commented out by default. The first thing I do is to un-comment it.
- Click the “Edit” link for the Ignore File
- The .gitignore file opens in the VS editor – scroll down to the “NuGet Packages Directory” section (lines 98-100 in my version) and remove the “#” sign from in front of “packages/”
- Save the changes
6. Commit and Push the .gitignore to Remote
- Click "Home" in the top bar of Team Explorer, then click "Changes"
- Enter a commit comment, then click "Commit"
- IMPORTANT: Click the "Sync" link (or "Unsynced Commits" link), THEN CLICK THE "SYNC" BUTTON. If you don't hit the Sync button there is no synchronizaztion - this is not very intuitive UI. Why do I have to click "Sync" twice? The deliniation between a hyperlink and a button is inconsistent in the Team Explorer GUI.
- You should be notified that you have “Successfully synchronized incoming and outgoing commits”. Your repository is now ready for other users to clone and contains the default .gitignore
- Your next step is to create a new solution/project and place it in the location where the .git repository resides. Changes will be picked up and you can commit/Sync to collaborate with your team.