Note: This document is a work in progress. You can help improve it.

Setting up a new project with GitHub

The dotnet CLI comes with a power scaffolding engine that provides a way for us as developers to create apps fast. Though the tools help us get started fast, they do not integrate with GitHub or git. This unopinionated set up is both a good and an annoying aspect. Since the pre-built tools are source control agnostic, we can other source control providers such as mercurial or svn, but this means that we to do a little extra work to get our projects on GitHub

step to create a new dotnet

Prerequisites:

Step 0: Create the project

To create a new .NET Core project, go to your terminal, and use the scaffolding tools to set up a new project with the following command.

dotnet new console -o HelloWorld

Note: HelloWorld is the name of your project. This command creates a new folder and put your new project in that folder.

Step 1: Set up the local git repo

After you have created your project, you want to get your code in git to track and save your changes.

In the directory of your project run

git init

This command sets up a new local git repository.

important: Do not commit yet as this commits files and folders we do not want in source control, such as the bin folder.

Step 2: Git ignore

After we set git, we tell git which files to put into source control. Usually, we only want our source code, not the compiled executables (.dll, .exe)

To add a .gitignore, we use an extension in Visual Studio Code.

  1. Open your project in you VS Code
  2. Open your command palette using the f1 button
  3. Run the command generate .gitignore.
  4. Select VisualStudio. This .gitignore file covers all the files that a standard .NET project has that we don't want in our source control.

Step 3: Create the repository on GitHub

After you set up your repository locally, you want to create that project on GitHub.

hub create

That creates a new project on Github.

Step 4: Commit

Create your first commit for your project using your favorite tool

Step 5: Your first push

Since this is a new project, for your first push, you need to set the default remote branch.

git push --set-upstream origin master

Summary

Now you have your repository set to like we are used to having.