Publishing an existing .NET (Core) project to Github

Creating a new Github repository in Visual Studio

I started working on my home automation project in 2020. I started with a simple backup script that copies the source code to a second hard drive, just in case the primary hard drive fails. When my code base started to grow I extended the script to create a (daily) second copy on OneDrive. From a backup perspective this is working fine, but it does not give me versioning and source control. Luckily, Github exists. Microsoft developed a Github extension for Visual Studio.

Make sure you update your Visual Studio installation before you install the extension. You also need to install Git for Windows. Additionally you need a Github account. After that, publishing an existing project to Github is pretty straightforward.

Open the command line and browse to the directory of the project. Execute a git init.

D:\>cd DataMario\Ontwikkeling\IoT\Verhaeg.IoT.Geofencing.Sensor

D:\DataMario\Ontwikkeling\IoT\Verhaeg.IoT.Geofencing.Sensor>git init
Initialized empty Git repository in D:/DataMario/Ontwikkeling/IoT/Verhaeg.IoT.Geofencing.Sensor/.git/

D:\DataMario\Ontwikkeling\IoT\Verhaeg.IoT.Geofencing.Sensor>

Open Visual Studio and copy/paste an existing gitignore file to exclude configuration files that could include passwords.

Then push the project to Git:

Push the project to Git service…

And finally, define the Git repository details.

Visual studio will offer you to create a Github repository.

Once you have published the project on Github you need to maintain it. There are three steps required to upload changes to the Github repository:

  1. Pull: pulls the latest version of the repository to the local development machine.
  2. Commit: commits the code changes to a “snapshot” of your project.
  3. Push: pushes the latest snapshot of your project to the repository.