Welcome back, everyone, to this lecture where we're going to discuss version control with Gates and
GitHub.
Now really, the final step is to be able to store a copy of our code on GitHub either publicly or privately
and then update our servers Django Project Code with any code if updated on GitHub.
Now, keep in mind, in order to follow along, you will need to create a free GitHub account before
continuing.
Speaking of which, you should really have some experience of GitHub and gets before continuing on.
So this lecture assumes some very basic knowledge of understanding what is actually used for and what
GitHub is used for and its overall use for version control.
If you really have no idea what I'm talking about when I mentioned the phrase GitHub or gets or even
version control, I would highly recommend that before you continue on with this lecture, go ahead
and just do the very basic Hello World tutorial that's on GitHub.
It's going to teach you a lot of the ideas on why you would want to use, get and hub and version control,
as well as the very basic commands to create a new repository, as well as push and pull changes to
it.
So if you've never done that sort of thing before?
Just take a little bit of time right now.
Go to this link or just Google search Hello World plus GitHub tutorial and go through that tutorial.
It's pretty quick, and it will explain why you would want to use GitHub and how to commit changes to
some repository and then pull those changes to another server.
Once you've done that, then you should be ready to go on actually connecting this Linux server to a
GitHub repository that we create.
So essentially, the steps that we need to do is have the S.H. connection to the node server install,
get on Leno, create a new GitHub repository on GitHub dot com and then connect Leno.
Get repo to GitHub and we will need to create a personal access token for that.
Then we want to be able to connect to GitHub repo locally.
That is on my local computer.
And then I want to be able to push and pull changes from a local computer to GitHub and then GitHub
to denote server.
All right.
So that's a lot of steps, but it's actually quite simple.
A lot of us just copy and paste in commands that hub tells us to do.
So let's get started by confirming our sausage connection to the Lennert server and then changing directory
to where our Django app folder actually is.
Let's get started.
All right.
Here I am back at my terminal, I've already done the SSA connection to my Linux server.
Next, what I want to do is actually need to navigate to the Django application folder, so we haven't
actually seen this yet.
But by going through the Leonard marketplace, a Django project was already started for us.
We confirmed that by visiting 8000 ports on our actual IP address, but we haven't seen the actual files
themselves.
So what I could do is I could CD or change directory into forward slash VR forward slash w w w.
Hit enter.
That's going to change directory into this particular slice of subdirectories, and then if you hit
L.S. for list, you should see the actual Django application.
This is the actual Django project that is currently running.
So what I can do is CD into Django App Folder.
Hit enter and then blessed to list everything that's in this folder.
And you should see a very basic project here we have DB sequel like Django app and Managed Pie.
And this is where the managed API is actually being run.
So essentially, Leno took care of a lot of work for us, and the Django app is actually already running.
You can confirm this by typing the command piece AWACS, and you should see somewhere around here something
being run by Python three managed Typekit run server at Port eight thousand.
So this is the actual line that's being run right now.
You can see a bunch of other stuff's been taken care of for us.
So just keep that in mind.
You don't need to worry about having to run Python, manage the server now.
Later on, we can't actually edit the settings that pie and then restart things ourselves in case we
need to.
So I'm going to clear this screen.
OK, so right now, I'm underneath Django app, and I want to create a new GitHub repository here in
order to do that.
I need to make sure I actually have installed gets to do that on Linux.
That's actually quite easy.
Simply say a pity dash.
Get space.
Install space.
G i t or get this is going to install gets onto our Linux server.
So enter here.
Notice for me.
I actually already had it installed for you.
If we're going to ask you if you want permissions to do it or not.
It's going to ask for about like 30 megabytes of space.
We have more than enough space for that.
So go ahead and just say yes.
And then it should install it.
And note, here I'm right now underneath the Django app.
OK.
So we just installed Gittes, which means I have the capability to create a Getz repository, but I
want to make sure that I actually connect that to GitHub.
That way, I have a place online where I'm actually storing my files and making sure everything's working.
So what you need to do now is go to GitHub dot com.
So here I'm going to come to bbc.com, and when you're logged in, go ahead and create a new repository.
Go ahead and pick out a repository name.
If you need some inspiration, you can go ahead and choose the one they suggest for you.
I'll just call this Django example, Leno.
And if you want this to be public or private, it's up to you.
I believe right now, GitHub of public and private are free for a single user.
If you want multiple users on a private repo, that's actually when you need to begin paying GitHub.
Slash Microsoft.
So I'll keep mine, actually keep mine public so you guys can see it later.
And then we could initialize this repository with fake ignore, read me etc, but we'll actually add
those on later on.
So leave all these blank and then I'm going to create a repository.
So this will now create a new repository.
And what's really cool about this is it actually has the instructions on how to create this new repository
on the command line.
Now, in order for this to work, we actually need to create what's known as a personal access token.
The personal access token will essentially allow us to have a password that will allow the little server
to push changes here to our example on GitHub to do that.
Go ahead and open up a new tab and go to GitHub.
And then at the top right.
Go to Settings.
Scroll down until you see developer settings.
Then go to personal access tokens.
Then you are going to click Generate New Token.
You can go ahead and give yourself a note as far as what's this token for?
So I'll say this is for lecture video Leonard.
You can also make this exploration for this token so I can make this expire in seven days, for example.
But most importantly, I need to understand the scope of what a server with this token password is able
to do.
So I want whoever has this password token be able to have full control of private repositories, so
select everything under repo, scroll down and then generate token.
And then go ahead and copy the token that's created for you.
Keep in mind, you don't actually ever get to see this token again, so make sure you copy it and save
it somewhere secure.
So later on, you can do more research on the best ways of storing this permanently.
Some encrypted fashion.
But just again, make sure you don't lose this.
Otherwise you'll have to recreate it again.
So I just copy this.
Maybe open up a notepad somewhere and paste it there for safekeeping right now.
So again, I can't really stress this enough.
Make sure you copy this before you actually go to another page.
So copy this and write this down on a quick notepad for right now to follow this example because we
will be copying and pasting something else in just a second.
The after this, once we leave this page, you will not be able to see this personal access token again,
and there's nothing I can do to help you with that.
OK.
So I just copied that, and now we need to do is come back here and then we're going to create a new
repository on the command line.
So go ahead and copy this set of commands.
This is going to initiate in your repository at a read me file.
Commit it and that's eventually going to add this and push this to this Django example A..
So copy and paste these commands with that little copy button.
Let's come back here and then I'm going to right click to paste that all in.
And then it's going to do a lot of configuration automatically for us, the very last line.
It's going to say, Hey, get push.
That's you, origin man.
Go ahead and hit.
Enter there.
It's going to ask for your username on GitHub.
Mines period data.
And then it's going to ask for your password, your password.
That is the password token that you just created.
So then go ahead and paste it in.
It's going to be invisible.
So I just pasted it in right now.
I enter.
And it should have been able to successfully push that to the Django example we saw.
So now you should be able to come back to GitHub here and refresh this.
And now you see your main branch.
Now, you may have noticed this just pushed the read me file, it didn't push anything else.
You actually want those jingo project folders as well.
So this is where your knowledge of gets at and get commit would come in handy if you haven't done that,
actually, the Helloworld tutorial, but what you should be able to do is essentially come back here
and at the command line, do something like get ad space dot and then say Get commits space.
I'm actually committing everything later on.
We probably want to ignore the actual DB sequel.
That's not something we want to be saving with Kit, but right now I'll just save it for the heck of
it and they'll say it.
Commit, um, my second commits.
Enter here.
And now it's saving all those again.
Later on, we're going to want to ignore some of these, like these pat cash files and squat like three,
so I can't say get push.
Hit enter.
And every time you push here, we'll ask you for your username, as well as that token password.
So go ahead and put that in.
And there you have it.
So now you come back to GitHub.
Refresh and you can see you have everything here, the database, read me, the M.D., manage that pie
and the Django app.
And now what you can do is make a local change and have that show up on the actual website.
So let me go ahead and do that now.
At this point, I would recommend downloading GitHub desktop, which makes it super easy to actually
download things locally.
So I already have a GitHub desktop set up on my own, so I'm going to open that up real quick.
All right, so if you haven't already Google, search GitHub desktop and download this tool, it's super
useful.
Technically speaking, everything I'm showing you or about to show you, you could just do yourself
at the command line, but it's just so much nicer with the desktop.
This GitHub desktop, a gooey, the graphical user interface that I highly recommend it.
So we're going to do is go ahead and download this GitHub desktop already.
Have my set up.
Mine's going to look a little more complicated than yours just because I have a bunch of repositories
connected to it.
But the main idea will be the same.
So eventually, what you're going to see after you download desktop is something that looks like this.
My apologies for the super small font here, but also meant to hopefully make it easy to see you're
going to click on Add Clone Repository.
Want to clone a repository?
Basically saying go to GitHub and clone a copy of the code?
I have there to be local here, so are going to say clone repository and then start searching on GitHub
dot com for the repository you just created.
Mine was called Django Example Leno, and then what you need to do is decide the local path of where
you want to save it.
So, for example, I'm going to choose to save it on my desktop underneath Django lectures.
I'm going to select that folder, OK?
And then once you've selected that notice, it's highlighted I've chosen the local path.
Go ahead and hit clone.
It's going to clone that actual repository locally, so I'm going to move this stuff out of the way.
And this is also where I will recommend having two screens.
Very helpful.
And then if you expand explorer, you should see Django example the node Django app.
Later on, we'll get rid of the steep SQLite.
I don't want to be constantly pushing and pulling the entire database.
That wouldn't make sense, so we want to add that to a ignore file later on.
Then we'll hit Django app and I can see everything that I'm already familiar with.
So let's keep this current PowerShell terminal open, and I'm going to add a new one command prompt,
which is now located here and Django lectures, and let's create a very simple landing page and make
sure everything is working.
All right, so this should feel really familiar now.
It's basically the environment you've been programming in.
All we can do is seed into our Django example, Leno.
And let's actually create a really small application that just returns back in response for some extended
URL.
So we can do here is just say, Python.
Manage the PI star app and let's call this app other.
So we'll enter there and we should see the other app created.
So here you have Django app and I see other app, and let's actually now connect this to our overall
Django application.
So what we can do here is everything we've done before in the past.
I'm going to create a new file under other called URLs that pay, and then what I can do here is just
make a really simple view.
So I got I've used up high and other and I'm going to say from Django, the HTP import HDP response.
So let's create a simple, function based view.
So simple view takes on a request, and there's simply going to return to response that says hello.
Then we'll go to your URLs and we'll save from Chengdu, the URLs import path.
And let's create our URL patterns list, as we've done many times before.
And then we'll say, here's path and then I need to actually import that view.
So we'll say from that.
Or actually, we can say from that, yeah, from that interviews, that should be fine, then we'll
create this path.
Just blink.
So when you go to essentially our domain, in this case, it's going to be our IP numbers port eight
thousand four slash other would be this particular view.
So blank here and then we need to connect it to the actual view.
So we'll see views dot and then it's simple view there.
OK.
If you want, you could give this a name, but just keep it super simple right now.
Essentially going all the way back to the very first single lectures.
So we have our oral patterns here.
I certainly connect this particular URL pattern to the overall website.
So you come to Django app and actually your URLs that pile here and we'll say from Django that URLs
import path, comma.
And then we also want to do is say include.
All right.
And then after this, we're going to say path.
And then say other forward slash.
And then we need to connect as include.
And we are going to include other URLs essentially following the same convention.
You always have.
All right.
So we have other that URLs connected to simple view, which itself is connect to the forward slash other,
so actually be something like that.
And then that connects the simple view, which should say hello.
So the question is, I need to now push these changes that I did locally to GitHub and then from Leonard
Pool.
Those changes it from GitHub so we can do this all, or at least the local stuff from our desktop.
So now bring in after you did all those changes that you now want to push to get help bring in your
little GitHub desktop tool and we'll ask you, OK, do you want to push all those changes?
That's going to be fine for us.
So we'll say first local changes here commit those to main and then push them to the origin.
Perfect.
So now we are going to come back to our secure shell here, and we're still located under the GitHub
repo.
If you want to run these commands again, you will need to CD into this repo location.
But then you should be able to say here.
Get cool.
And it's going to pool all those changes we just made.
OK, perfect.
So that just pulled in those changes from GitHub.
And then now when you go to your actual Lennart page, you should actually now see a 404 error.
You should definitely not have debug when you actually launch your website on.
So just the heads up there.
You don't want your users to actually get a page that looks like this.
So right now, that's OK for us because we're just testing.
Remember, you can always go to settings and turn debug false, and then we're going to say forward
slash other.
And now I see.
Hello.
But notice the IP here, this is a real live web site.
And as long as I keep this running, anybody can just go to this website for each other and see hello.
And then later on, if you want or to, you can connect this to your own domain name.
But we did essentially most of the heavy lifting so far.
There's still a bunch of little details to discuss, and I'll leave some articles as well as some lecture
links for you in the next article lecture that are really useful.
Things like setting up ignore had actually go through deployment things like remember to set debug equal
to false, that sort of thing.
But really the core of it is done.
We were able to create a Linux server that's a computer somewhere set in Dallas, Texas.
I was able to set up a hub repository and then I was successfully able to link that computer in Dallas
to wherever that hub repo is somewhere hosted by Microsoft and then to my local computer.
So there's essentially when you think about it, three little computers interact with each other.
There's my local computer pushing a GitHub, and then there's a little server pulling from GitHub,
and all that works essentially magically almost to show hello on the internet.
And that is how the web works.
OK.
Thanks.
And I'll see you at the next lecture.