WEBVTT

00:00.000 --> 00:00.240
Okay.

00:00.270 --> 00:06.600
Our final task of this section is to save our hard work into source control.

00:06.600 --> 00:09.030
And there's many good reasons to do this.

00:09.060 --> 00:10.800
It makes our code more portable.

00:10.800 --> 00:17.070
And if we change or move on to a different computer, we can simply clone our project from a publicly

00:17.070 --> 00:18.150
available repository.

00:18.180 --> 00:22.470
We don't need to copy our files across a network onto a hard drive.

00:22.470 --> 00:29.460
Whatever method we choose, we can simply get our latest version of our code from a public repository.

00:29.490 --> 00:36.450
Also, if disaster happens and our computer dies along with our hard drive, then we've got an easy

00:36.480 --> 00:37.860
way to recover our code.

00:37.860 --> 00:43.440
It's still a disaster in terms of the computer breaking, but our code is safe because we've saved it

00:43.440 --> 00:48.150
into a cloud based repository for storing our code.

00:48.150 --> 00:49.410
And we'll do that now.

00:49.410 --> 00:54.720
And we'll do this every time we reach certain milestones in this course, such as when we get to the

00:54.720 --> 00:55.830
end of a section.

00:55.830 --> 01:03.530
So inside VS code, we do have a source control tab and we do need to have git installed into our computer

01:03.530 --> 01:06.560
to see what I'm seeing right here.

01:06.590 --> 01:10.100
So please ensure that you do have git installed from git.

01:11.390 --> 01:15.710
And if you have, then you'll see this option to initialize the repository.

01:15.710 --> 01:17.330
So I'm going to click this button.

01:17.330 --> 01:22.820
And this effectively starts tracking all of our code inside our project.

01:22.850 --> 01:27.590
Now it's currently tracking too much because there's a lot of code inside here that we didn't write

01:27.620 --> 01:28.640
ourselves.

01:28.640 --> 01:30.350
And this is stuff that the.

01:30.530 --> 01:33.500
Net compiler creates on our behalf.

01:33.500 --> 01:39.290
Now we don't need to save things that we haven't generated ourselves, or written the code ourselves

01:39.290 --> 01:40.580
into source control.

01:40.640 --> 01:44.870
That just makes our project bigger and more noisy than it needs to be.

01:44.870 --> 01:48.980
So we don't need all of these changes that it's picked up so far.

01:48.980 --> 01:55.040
But there is something that we can use from the dotnet SDK to help us reduce that noise.

01:55.130 --> 02:02.010
And I'll just open up a new tab inside here, and I need to go up to the solution level.

02:02.040 --> 02:05.190
So please make sure you're at the restore folder level.

02:05.190 --> 02:12.090
And if I just type in dotnet new list, then one of the things that we can use inside here is this dotnet.

02:12.120 --> 02:13.830
Gitignore file.

02:13.830 --> 02:15.870
And this will ignore the common things.

02:15.870 --> 02:21.810
We want to not save into a public GitHub repository and reduce the number from 165.

02:21.840 --> 02:24.030
In my case to something a bit more manageable.

02:24.030 --> 02:28.680
So we're going to use this and inside the terminal.

02:28.680 --> 02:30.840
And please make sure you're at your solution level.

02:30.840 --> 02:34.140
When you do this we're going to say dotnet new.

02:34.170 --> 02:37.560
Gitignore and press return.

02:37.590 --> 02:39.150
This creates that file.

02:39.150 --> 02:44.550
And notice that this is now reduced from one in my case 165 to 18.

02:44.550 --> 02:51.360
And these are the files where we do have or code that we do want to save into source control.

02:51.390 --> 02:58.500
Now at this stage as well, we might want to exclude further elements from inside here.

02:58.530 --> 03:04.110
Now we don't necessarily we wouldn't normally store a database inside a public repository, so we might

03:04.110 --> 03:05.580
want to exclude the database.

03:05.580 --> 03:06.750
You can do if you want.

03:06.780 --> 03:10.350
I'm just going to leave it there because that makes the code even more portable.

03:10.350 --> 03:14.520
If I move on to another computer, then I've already got the database there as well.

03:14.550 --> 03:18.210
But as we've seen, we can easily create this regardless.

03:18.210 --> 03:22.050
So it's not essential to store the database file there, but it's up to you.

03:22.080 --> 03:27.720
One thing that I would recommend that you remove so that you've got a place to store secret information,

03:27.750 --> 03:29.130
things like API keys.

03:29.160 --> 03:31.500
Is this appsettings.json?

03:31.500 --> 03:38.580
If we exclude this from our public GitHub repository, then it becomes a kind of safe place to store

03:38.610 --> 03:42.180
API keys for services that we might use later on.

03:42.210 --> 03:46.050
So I'm going to right click this file and say add to.

03:46.080 --> 03:51.330
Gitignore to exclude it from what we save into our source control.

03:51.360 --> 03:55.140
But everything else is fine and we would want to save.

03:55.170 --> 03:59.760
So if we do move on to another computer then it's pretty easy to get back up and running because we'll

03:59.760 --> 04:04.890
get all of these files easily accessible to us whenever we need to.

04:04.920 --> 04:07.830
So we'll give it a commit message, which we enter in this box.

04:07.830 --> 04:11.430
And I'm just going to say end of section two in this case.

04:11.430 --> 04:13.260
And then I'm going to click commit.

04:13.260 --> 04:16.620
And not yet actually we need to stage the changes.

04:16.620 --> 04:20.580
So where we've got changes let's just click this plus button.

04:20.580 --> 04:23.130
And this stages those changes.

04:23.130 --> 04:24.990
And then we can commit.

04:24.990 --> 04:27.660
And then we can publish our code to GitHub.

04:27.660 --> 04:30.420
But before we do that let's go to GitHub itself.

04:30.420 --> 04:32.700
And please go to github.com.

04:32.700 --> 04:39.840
And if you do not have an account with GitHub please go ahead and create one and get yourself to the

04:39.840 --> 04:42.060
roughly the page I'm on now.

04:42.060 --> 04:46.680
And then we can click the plus button and we'll say new repository.

04:46.680 --> 04:52.710
And I'm going to give it a name of restore which is already gone because I'm updating this course and

04:52.710 --> 04:55.860
really creating a new version of this training course.

04:55.860 --> 05:02.580
So I'm going to say Dash v2 for this one, and I'm going to leave it as public, which means anyone

05:02.610 --> 05:04.530
on the internet can see this repository.

05:04.530 --> 05:08.490
But you choose who can make changes, who can commit to this repository.

05:08.490 --> 05:11.100
And I'm going to say create repository.

05:11.100 --> 05:16.740
And once this has been done then we've got our git init git add readme.

05:16.770 --> 05:17.760
But we won't do that.

05:17.790 --> 05:21.480
We've done our git commits the git branch.

05:21.480 --> 05:24.000
We might want to change that if we need to.

05:24.030 --> 05:30.810
And if I take a look at my terminal, I can see that the branch name has been called main.

05:30.810 --> 05:33.870
If yours has been called master, you might want to run this command.

05:33.870 --> 05:40.440
Just say git branch main, which will effectively change it to main if it hasn't been done so already,

05:40.440 --> 05:44.370
as master is going to get removed from the terminology at some point in the future.

05:44.370 --> 05:47.280
And then we have git remote add origin.

05:47.280 --> 05:54.390
Just copy this line into your clipboard and go back to the terminal and just paste in that line to add

05:54.390 --> 05:59.190
the remote address of your GitHub repository and press return.

05:59.640 --> 06:03.550
And then we can use the publish branch option.

06:03.550 --> 06:05.350
So I'll click Publish Branch.

06:05.470 --> 06:09.610
And you may have to authenticate with GitHub at this point.

06:09.790 --> 06:12.430
And once you've done that you should be able to go back to the browser.

06:12.430 --> 06:18.370
Refresh the page and you should see your code inside the public GitHub repository.

06:18.370 --> 06:24.160
And if you did want to move on to another computer, then your code is very easily accessible.

06:24.160 --> 06:32.830
Just click this green button, copy the link, and then inside the terminal you can just say git clone

06:32.830 --> 06:35.440
followed by the address that you've done there.

06:35.440 --> 06:40.840
I'm not going to do that because I don't want another copy of my project inside this folder, but that's

06:40.840 --> 06:45.460
how you would move your code onto a different computer once you've committed it into GitHub.

06:45.460 --> 06:51.490
So that brings us to the end of this first coding section where we've set up our API.

06:51.490 --> 06:57.610
And now we're ready to really start creating our user interface side of our project.

06:57.610 --> 07:01.480
And before we get to that, we'll just wrap up this section with a summary.
