Until now, we worked with a local installation of git and everything was good but once we start working on a project together with someone else we’ll soon discover that we need a way to share our work with other members so working offline is no longer an option.
It’s now time to go online, and in this post we’ll use GitHub as service for host and share our projects.
In order to user GitHub we need to have an account, if you don’t have one, navigate to https://github.com and register:
Image may be NSFW.
Clik here to view.
once registration is completed, login and click Start a project button to create a brand new repository, fill form with your data
Image may be NSFW.
Clik here to view.
the click Create Repository to create it, after a moment you will have the uri to GitHub repository
Image may be NSFW.
Clik here to view.
Now is time to add to Visual Studio plugin the capability to connect to GitHub repository, if not already present go to Tools->Extensions and Updates, select Online on left column and using search box in upper right corner and type github.
The first result should be the extension you need:
Image may be NSFW.
Clik here to view.
Select it and click Download to install it, then restart Visual Studio to complete installation.
Now go to Team Explorer, click on the green plug in top toolbar and connect to your GitHub account
Image may be NSFW.
Clik here to view.
Sign in with GitHub credential to complete connection of Visual Studio to GitHub.
We can now create or clone a new github repository, let’s clone the repository we created before by clicking clone above GitHub connection.
Image may be NSFW.
Clik here to view.
we are now prompted with a list of our repositories, including the one we just created
Image may be NSFW.
Clik here to view.
select and click Clone, we’ll now have an empty GitHub project inside Visual Studio, time to add a blank solution using File->New->Project->Other Project Types->Visual Studio Solutions
Image may be NSFW.
Clik here to view.
We’ll now see our blank solution inside Solution Explorer
Image may be NSFW.
Clik here to view.
Time to add a new project, let’s add a Console Application Project, right click the Solution->Add New Project->Windows Classic Desktop->Console Application
Image may be NSFW.
Clik here to view.
and click Ok, the project will be listed under our solution now
Image may be NSFW.
Clik here to view.
From the “+” on the left of the items you will now recognize that items are added to local git repository but not committed, let’s add a comment and try to commit the changes
Image may be NSFW.
Clik here to view.
Wait! there’s a problem!, what are those files? we don’t need them to be tracked! but since we didn’t added a .gitignore file, git will track all files that are part of our solution.
Let add it before committing the project: In Team Explorer, click Settings->Repository Settings and click Add button next to Ignore File
Image may be NSFW.
Clik here to view.
If we now go back to Changes tab, we’ll see this status, and only files making up our solution will be now tracked
Image may be NSFW.
Clik here to view.
Let’s click Commit Staged to commit staged and the Commit to complete the commit phase.
Ok, our new project is now tracked by local Git, how to we sync with GitHub?
Let’s select Sync tab, we’ll see something like this picture
Image may be NSFW.
Clik here to view.
Let’s click Push to push changes to GitHub and let’s see how they appear on GitHub portal
Image may be NSFW.
Clik here to view.
It is an online copy of our local repository.
Let’s add a property to P1 to Program.cs, commit and push the change, we’ll now see the latest commit listed
Image may be NSFW.
Clik here to view.
Let’s make a branch dev, and let’s push it, if we have a look online we will see it listed under branches dropdown list
Image may be NSFW.
Clik here to view.
It is now evident that GitHub now acts as online hub for all push operation from different team members and relative pull operation when members need to retrieve changes pushed by other developers.
Of course, if two developers works on the same part of code during pull operation conflicts might happen and need to be fixed.
We’ll talk about that… Image may be NSFW.
Clik here to view.