Instructor: All right, so whereas in the last lesson,
we were looking at local implementations
of using Git and version control.
In this lesson, we're gonna talk about how you can create
a remote repository,
so a repository that's hosted on somebody else's server
or somebody else's computer by using GitHub.
Now most people would have heard of GitHub
and certainly by now, you would have used GitHub many times.
So if you haven't yet set up an account on GitHub,
then this is the time to do it.
So head over to github.com
and simply fill out this quick form
to create an account on GitHub.
It's completely free
and all you need to do is just confirm your email
so that you can access it.
Once you've done that, go ahead and sign in.
Once you've signed in, you should be looking at this page.
And what we're gonna do
is we're going to create a repository
inside the browser-based GitHub.
So if you navigate to this top right corner
and click that plus arrow,
then you can select new repository.
And I'm gonna call my repository same name,
I guess we'll call it Story.
And let's give it a description.
Let's say my masterpiece.
Now by default,
all repositories that you create on GitHub are public.
That means that anyone can see all of the files
inside your save repository.
Everything that you commit to your remote repository
or to your GitHub repository will be public.
If you don't want that, then you can select private.
But in most cases,
if you're not doing anything that's top secret
or if you're not developing technology
that is completely brand new,
then having a public repository is not such a big problem.
And on the other hand as well
you can see loads of other people's public repository
and you can see for example how they structure their code,
what is their style and you can see how people do things.
For example on GitHub, there are whole repositories
on things like Flappy Bird.
So it's the entire implementation of a Flappy Bird
and you can run it or you can also
look through their code base to see how they did this.
This is the beauty of open source code.
And as you develop in your journey of becoming a developer,
then you might find that you want to contribute
to other open source projects.
Help them out a bit and work in a virtual team
to try and contribute your knowledge
and your programming skills.
Okay so, once I've selected public,
the next thing is that I'm gonna leave this part empty.
I'm not going to initialize a read me
for my repository just yet.
The next thing is that I'm gonna go ahead
and click the big green button and create my repository.
Now you can see that there are two ways that they tell you
you can set up your repository.
You can either set it up in GitHub on desktop,
their desktop client, which I am not a big fan of.
But instead, what we're gonna do
is we're gonna use the command line instructions
to set up our repository.
So we are going to push an existing repository
that we've got locally
onto this remote repository.
And to do that,
we need to copy the address of our GitHub repository
and we're going to use these two lines of code
in order to transfer or push our existing local repository
from the command line.
All right, I'm currently inside my story directory
which also happens to be the working directory
for this particular project.
And here, I am going to again take a look at Git log
to see what previous commits we've got.
And you can see that we've got two previous commits.
And I would like to push both of these commits onto GitHub.
To do that,
the first thing is creating a remote.
So it's telling my local Git repository
that I've created a remote repository
somewhere on the internet
and I want to transfer all of my commits over there.
So the command that we're gonna use
is git remote add origin.
Now origin is simply the name of your remote
and you can theoretically call it anything you want.
You can call it bacon if you want
but by convention and it's highly recommended
that you simply keep the name origin.
And the reason is because most programmers are used
to the conventional naming
and that means it'll be much easier for them to understand
what's going on in your project
when they have a look at it
instead of you doing something completely different
which will be very surprising
and it'll be a lot harder for people to understand
what's going on.
So git remote add origin
and then we're going to paste the URL
of our remote repository on GitHub
and then we're gonna go ahead and hit Enter.
And now that remote is created.
So we can push our local repository
onto our remote repository which is called origin.
So we're gonna say git push -u origin main.
And what this line of code does
is that it pushes your local repository
to the remote repository
using the U flag or the U option
which basically links up your remote
and your local repositories.
And then we're going to push it towards the remote
that's called origin.
And we're going to push it to the branch that's called main.
The main branch is simply the default branch
or the main branch of all of your commits.
And later on when we cover branching,
then we're gonna talk more about what is a main
and what is a branch.
But for now,
we're just saying that we're going to push
our local repository onto this origin remote
and we're going to push it to the main branch.
So let's go ahead and hit Enter.
And there's gonna be a little bit of work being done
in the background
because it's actually going to have to upload
your local repository to the remote repository
on GitHub servers.
And depending on the size of your local repository,
this can take various amounts of time.
Now once we see our prompt, so the flashing cursor
or the dollar sign,
that means that our push is successful.
And as you can see it says
Branch main set up to track remote
branch main from origin.
Sounds really confusing.
But if you head back over to GitHub
and if you're on the same page,
all you have to do is hit Command+R to refresh
or just press the Refresh button.
And you can see that all of our files
are now hosted on GitHub
and it's complete with all of our commit messages.
So if you go into Insights and go into Network,
you can actually see our main branch
which currently only has two savepoints or two commits.
And if you hover over them,
you can actually see the commit messages of each of these.
As you build out your project,
as you add more commits,
either locally or pushing it remotely or probably doing both
then you can see the progress of your files
in your GitHub repository.
So now, you can see all of the code if it's code file
or in our case it's just a text file,
hosted on GitHub.
And you can point anybody towards this.
And there are actually cases
where people do a lot of story writing using GitHub
just because it's so good at tracking your savepoints
and being able to revert to previous versions in the past.
So for example, if you head over back to the main page
and you go to your commits,
you can see both of those commits, when they were committed.
And also if you click on it,
you can see the changes that were made at those time points.
So if we have a look at chapter one,
you can see this is all we had
at the point when we made our first commit.
Previously, we said that we have a working directory
which is the directory where we initialized Git.
Then we can push our files to a staging area
where we can pick and choose which files we want to commit.
Then once we're ready, then we can commit our files
or our savepoint to our local repository.
So once you've done a few commits,
then you actually have this timeline of various commits
and this is called your main branch.
So the main branch is your main branch of commits
or savepoints
and it is sequential.
And this is usually where your main progress
is saved or committed.
Later on, we then introduced this idea
of the remote repository.
The important thing to note is that
you can have a local repository completely in parallel
with a remote repository,
check the differences between them
but you can also sync them or push things
from your local repository to your remote repository.
So in our case, the local repository is the Git file
that we've got inside our story directory.
And the remote repository is GitHub
which hosts our code and also hosts all of the changes
that were made in between the different commits.
So we have this main branch of various commits:
first commit, second commit, third commit
in our local Git repository.
And when we performed the command git to push,
then that effectively pushed all of those commits,
all of those various versions and changes and code pieces
to our remote repository on GitHub.
So that's what git push does.
Now in the next lesson, I wanna talk about using gitignore
and how you can avoid uploading
sensitive pieces of information such as API keys
or passwords to your remote repositories,
for example, GitHub.
So all of that and more on the next lesson.
See you there.