Okay.
Our final task of this section is to save our hard work into source control.
And there's many good reasons to do this.
It makes our code more portable.
And if we change or move on to a different computer, we can simply clone our project from a publicly
available repository.
We don't need to copy our files across a network onto a hard drive.
Whatever method we choose, we can simply get our latest version of our code from a public repository.
Also, if disaster happens and our computer dies along with our hard drive, then we've got an easy
way to recover our code.
It's still a disaster in terms of the computer breaking, but our code is safe because we've saved it
into a cloud based repository for storing our code.
And we'll do that now.
And we'll do this every time we reach certain milestones in this course, such as when we get to the
end of a section.
So inside VS code, we do have a source control tab and we do need to have git installed into our computer
to see what I'm seeing right here.
So please ensure that you do have git installed from git.
And if you have, then you'll see this option to initialize the repository.
So I'm going to click this button.
And this effectively starts tracking all of our code inside our project.
Now it's currently tracking too much because there's a lot of code inside here that we didn't write
ourselves.
And this is stuff that the.
Net compiler creates on our behalf.
Now we don't need to save things that we haven't generated ourselves, or written the code ourselves
into source control.
That just makes our project bigger and more noisy than it needs to be.
So we don't need all of these changes that it's picked up so far.
But there is something that we can use from the dotnet SDK to help us reduce that noise.
And I'll just open up a new tab inside here, and I need to go up to the solution level.
So please make sure you're at the restore folder level.
And if I just type in dotnet new list, then one of the things that we can use inside here is this dotnet.
Gitignore file.
And this will ignore the common things.
We want to not save into a public GitHub repository and reduce the number from 165.
In my case to something a bit more manageable.
So we're going to use this and inside the terminal.
And please make sure you're at your solution level.
When you do this we're going to say dotnet new.
Gitignore and press return.
This creates that file.
And notice that this is now reduced from one in my case 165 to 18.
And these are the files where we do have or code that we do want to save into source control.
Now at this stage as well, we might want to exclude further elements from inside here.
Now we don't necessarily we wouldn't normally store a database inside a public repository, so we might
want to exclude the database.
You can do if you want.
I'm just going to leave it there because that makes the code even more portable.
If I move on to another computer, then I've already got the database there as well.
But as we've seen, we can easily create this regardless.
So it's not essential to store the database file there, but it's up to you.
One thing that I would recommend that you remove so that you've got a place to store secret information,
things like API keys.
Is this appsettings.json?
If we exclude this from our public GitHub repository, then it becomes a kind of safe place to store
API keys for services that we might use later on.
So I'm going to right click this file and say add to.
Gitignore to exclude it from what we save into our source control.
But everything else is fine and we would want to save.
So if we do move on to another computer then it's pretty easy to get back up and running because we'll
get all of these files easily accessible to us whenever we need to.
So we'll give it a commit message, which we enter in this box.
And I'm just going to say end of section two in this case.
And then I'm going to click commit.
And not yet actually we need to stage the changes.
So where we've got changes let's just click this plus button.
And this stages those changes.
And then we can commit.
And then we can publish our code to GitHub.
But before we do that let's go to GitHub itself.
And please go to github.com.
And if you do not have an account with GitHub please go ahead and create one and get yourself to the
roughly the page I'm on now.
And then we can click the plus button and we'll say new repository.
And I'm going to give it a name of restore which is already gone because I'm updating this course and
really creating a new version of this training course.
So I'm going to say Dash v2 for this one, and I'm going to leave it as public, which means anyone
on the internet can see this repository.
But you choose who can make changes, who can commit to this repository.
And I'm going to say create repository.
And once this has been done then we've got our git init git add readme.
But we won't do that.
We've done our git commits the git branch.
We might want to change that if we need to.
And if I take a look at my terminal, I can see that the branch name has been called main.
If yours has been called master, you might want to run this command.
Just say git branch main, which will effectively change it to main if it hasn't been done so already,
as master is going to get removed from the terminology at some point in the future.
And then we have git remote add origin.
Just copy this line into your clipboard and go back to the terminal and just paste in that line to add
the remote address of your GitHub repository and press return.
And then we can use the publish branch option.
So I'll click Publish Branch.
And you may have to authenticate with GitHub at this point.
And once you've done that you should be able to go back to the browser.
Refresh the page and you should see your code inside the public GitHub repository.
And if you did want to move on to another computer, then your code is very easily accessible.
Just click this green button, copy the link, and then inside the terminal you can just say git clone
followed by the address that you've done there.
I'm not going to do that because I don't want another copy of my project inside this folder, but that's
how you would move your code onto a different computer once you've committed it into GitHub.
So that brings us to the end of this first coding section where we've set up our API.
And now we're ready to really start creating our user interface side of our project.
And before we get to that, we'll just wrap up this section with a summary.