GitHub Tutorial for Beginners (2025)
By CodeWithChris
Summary
Topics Covered
- A commit is undo for your entire project
- An online repo survives when your hard drive dies
- Discard instantly reverts to your last good commit
- Branches eliminate any risk to your main project
Full Transcript
If your project has ever broken, it's gotten so bad that you have to restart from scratch and you would give anything for just an undo button to go back in time. This video is to give you that.
time. This video is to give you that.
And you can use this even if you have never coded before or you're just a beginner. The answer, it's called source
beginner. The answer, it's called source control. Now, I'll explain to you what
control. Now, I'll explain to you what that is in a moment. But first, has this situation ever happened to you? You're
coding with AI and AI just messes up your project so bad. You try to undo and go back in the conversation history.
Nothing works. Your project doesn't build and you don't know what to do. Or
maybe you're coding by hand and you've coded your way into a dead end with no easy way to go back. Maybe you've been backing up your project by creating multiple copies of your project in
different folders. Let me tell you,
different folders. Let me tell you, there's a better way. By the end of this video, using source control, you'll be able to save snapshots of your project as you go along, and you can restore
from any version of these snapshots in your history in case something goes sideways. You will never have to start
sideways. You will never have to start from scratch again. You'll also be able to try wild ideas or experiment with new features on separate copies of your project called branches. And this
ensures that your main good working copy of your project never gets broken. Or
maybe you're working on your project from multiple computers. Source control
will allow you to stay in sync between the two. Or if you're working with other
the two. Or if you're working with other people, you can collaborate on the same codebase efficiently without overwriting each other's code or creating conflicts.
So what is source control? You can think of source control as a vault containing your code that sits in the cloud. You
have your main good copy of your project and you have previous versions as snapshots. you can go back and restore
snapshots. you can go back and restore any snapshot really really easily and essentially just go back in time to a previous state of your project. There
are different kinds of source control, but one of the most common ones is called Git. And GitHub is a free and
called Git. And GitHub is a free and easy way to use it. Even professional
software developers use GitHub to maintain and collaborate on their projects. But don't worry, I'm going to
projects. But don't worry, I'm going to make it super easy for you so that you can benefit from the features as well.
All right, let's jump in. All right,
step one. You have to create your free github.com account. So, go to
github.com account. So, go to github.com. Click on sign up. You can
github.com. Click on sign up. You can
even enter in your email right here. I'm
sure it'll just bring you to this page.
You got to add your password, your username, and your country. And go ahead and create your account. One more thing, if it gives you options on what plan you want to select, just select the free
plan. That's all you need. Next, go to
plan. That's all you need. Next, go to desktop.github.com github.com and
desktop.github.com github.com and download the GitHub Desktop software.
This app is going to make it really, really simple to use GitHub. Once you've
downloaded the GitHub Desktop app, launch it. Yours might not look like
launch it. Yours might not look like this on the first launch. Maybe you'll
see something that says sign in or create an account. Go ahead. You want to sign in to the account that you just created. If you don't see anything about
created. If you don't see anything about signing in or signing up, go to GitHub desktop menu at the very top. Go to
settings and then we're going to want to sign in through accounts right here. So
you can go ahead sign in. It's going to open up your browser. Then you can go ahead and just sign in. And if you're
already signed in, which you should be because you just created the account, then you are now good to go.
All right, now we're going to move on to step three. Before we go any further, I
step three. Before we go any further, I need to explain how source control works so that the next steps make sense. So
earlier I used the analogy of a vault that stores your code. So the actual term for this is repository or repo.
Now, each repo is for a single code project, but you can make as many repos as you want. Now, inside of a repo, I also mentioned that you can save snapshots of your project as you go
along. And that way, you can always go
along. And that way, you can always go back if you make a mistake. It's like
hitting undo, but for your whole project, not just for one file. You can
always go back to a previous snapshot.
The actual term for a snapshot is called a commit. Earlier I also said that the
a commit. Earlier I also said that the vault or repo lives in the cloud. This
is where GitHub comes in. GitHub is that online cloud version of your repo. What
I didn't mention is that repos can also be locally on your computer. In fact,
that's how it often starts. You first
create a repo on your computer to store your project. This way you can still
your project. This way you can still have those snapshots or commits and you can go back in case you mess something
up and then at any time you can publish that repo to GitHub and now you have an online cloud version of that repo as well. And there are multiple benefits
well. And there are multiple benefits for having an online repo. Number one,
it serves as a backup. If your computer hard drive dies and that's the only copy of your project, even if it's on a repo on your computer, you'll lose it. But if
you have an online repo, at any point in time on your new computer, you can pull a copy of that code down. Another
benefit is if you work on multiple computers, some people have a desktop and a laptop, and sometimes you want to switch between them. Having an online
repo keeps your project in sync across multiple computers and that leads to the ability to collaborate with other people as well. If you have multiple partners
as well. If you have multiple partners or teammates working on the same project, you're going to need an online repo so that everyone can stay in sync.
So, in the next few steps, I'm going to show you how to create a local repo first and then how to publish it on GitHub and then also how to take
snapshots or commits so that you can save your progress and undo at any time.
All right, now let's try it out. So,
let's start by creating the repo locally on our computer. We are going to go to file, new repository, and we're going to give this a name.
Typically, this will be our project name. So, I'm just going to call it test
name. So, I'm just going to call it test repo.
That you don't have to give a description, but you do have to choose a local path. Where do you want to store
local path. Where do you want to store your project? What this will do is
your project? What this will do is create a folder wherever you specify this location to be. So, right now, it's the desktop. It's going to create a
the desktop. It's going to create a folder on my desktop called test-reo.
And inside of there, we are going to store all of our project files. So, make
sure that this path is where you want to store your app projects.
We're also going to want to check this and initialize the repository with a readme file. This is typically just
readme file. This is typically just contains information about the project or instructions on how to use the project. Think of it as a notes file
project. Think of it as a notes file that accompanies your project. Now, for
this next drop-down, git ignore, what is this? This is a file that allows you to
this? This is a file that allows you to specify which project files not to include in the snapshot or commit. The
reason for this is because there's a lot of specific user files that don't need to be in the project. Let's say that you're working on the project with
multiple teammates, right? If every
teammate adds their own personal user or settings files with the project, then it doesn't make sense, right? You want the code files. You don't want all of these
code files. You don't want all of these settings files that are specific to a single user. So this get ignore file
single user. So this get ignore file allows you to specify which files not to include into the commit. And there are some presets that we can choose from.
And because the viewers of this channel, we specialize in Swift programming language for developing iOS apps, I'm going to choose Swift here. But whatever
language you're working in, you're going to want to choose that preset. You can
always open up this git ignore file.
It's just like a text file. and you can go and add additional files that you want to ignore. But the preset is a good place to start. Okay, so this last line
tells us the repo will be created at this location. And notice that there is
this location. And notice that there is a folder name, exact name of our repo.
So I'm going to go ahead and create that repository.
And just like that, if I look on my desktop, we have I have so many test folders that it's a little hard to see, but here it is.
Okay. So, it's just got a readme file.
And if I open this in a text editor, you're going to see all it contains is this. You can add notes here in markdown
this. You can add notes here in markdown format. If you're not familiar with
format. If you're not familiar with markdown format, if you're not familiar with markdown, it's really simple. Just
Google for a a glossery. You don't even need a tutorial for this, but you just need to know what the symbols mean. And
most of it is just text, actually. So
that's our repo. It's empty right now.
Let's go ahead and create a new project and put it inside the repo. If you
notice here in the GitHub desktop app, your current repository should be the one that you just created, which is specified here. If you tap on this, it
specified here. If you tap on this, it allows you to choose from different repositories, but we're going to leave it at the one we just created. And you
see this button here, publish it to GitHub. that's pushing the commits and
GitHub. that's pushing the commits and making our local repo an online repo as well. And then we're not going to do
well. And then we're not going to do that just yet. Let's go ahead and create our project. And now we get to step
our project. And now we get to step five, which is to create our project and our first commit and then to publish it to GitHub. So let's start by opening up
to GitHub. So let's start by opening up Xcode and creating a new project. And
we're going to choose iOS app. We're
going to call this the same thing as our uh repo name. Typically, that's what you do. I'm not going to go over these other
do. I'm not going to go over these other project settings because they don't matter for the purpose of this video, but the next setting does matter right here. So, you're going to want to leave
here. So, you're going to want to leave this unchecked because you're using GitHub Desktop to create your local repo.
Now, you have to save this project into the repo folder that we created. So, I
created mine on the desktop. Here it is, test-reo. So, I'm going to go ahead and
test-reo. So, I'm going to go ahead and click into it. You can see the reree file right there. And actually, if you take a look at this, this is uh blanked
out. You cannot enable this because it
out. You cannot enable this because it recognizes that this folder is already a local repo. Okay, so if you're doing
local repo. Okay, so if you're doing things right, if you're in the right location, this should be blanked out and you can't even select it. Now, go ahead and hit create.
It's going to create your project in there. So, here we have our new Xcode
there. So, here we have our new Xcode project. But if you go back to GitHub
project. But if you go back to GitHub desktop, you'll see that it recognizes since your last save, which was the initial
creation of the repo, you've done these changes. This is a great way to look at
changes. This is a great way to look at what changes have been made since the last save. So, we added all of these new
last save. So, we added all of these new files because these are all the new project files that Xcode just created for us. So, let's create our first
for us. So, let's create our first snapshot or commit. And what we do is come down here and we want to write a note of what's changed. So you can call
this the initial project commit.
And then you're going to hit this button, commit eight files to main. Main
is the name of the default branch. We'll
get into branches in the next project.
You don't need to worry about that right now. Just know that what you've done is
now. Just know that what you've done is you've if you go to history you have taken a snapshot.
So actually when we created the repo there was an initial commit and we call the next commit that we created the initial project commit which contains all our project file. But now all you
have to do is hit this button publish to GitHub. So, what'll happen when I tap on
GitHub. So, what'll happen when I tap on this is it's going to take this local repo and create an online version of the repo. If you go back to the GitHub
repo. If you go back to the GitHub account that you created in the browser, you'll probably see no repositories here under your account. But after we hit
publish, which I'm going to do right now, um you're going to see it here. There
are some settings. I would advise you to keep this private even if you are sharing it with teammates because if you uncheck this, it's actually public and everybody can see it. So you don't want
that. You want to be able to control the
that. You want to be able to control the access. So go ahead and hit keep this
access. So go ahead and hit keep this private. You can give it a description
private. You can give it a description if you want. And then go ahead and hit publish repository and it's going to be published to github.com.
github.com.
So after you do that, let's go to github.com. Hit refresh and you're going
github.com. Hit refresh and you're going to see your new repo. So for me, it's right here. If you click it, you're
right here. If you click it, you're going to see all of our project files now up here. So congratulations. You've
made your first commit and you've published your first online repo. Next,
let's take a look at making a change and then restoring. Okay, so now we move on
then restoring. Okay, so now we move on to step six where we are going to make a change in our project and I'll show you how to make a new snapshot or commit and and then we're going to revert to show
you how to go backwards. So when would you want to make a commit? Usually when
you finish a feature or you know it's a good stopping point and you want to save your progress. You wouldn't want to make
your progress. You wouldn't want to make a commit halfway through like writing a line of code, right? So I'll leave that up to you. But what you would do is let's say I change something here. I'm
just going to make a trivial change. I'm
just going to say hello Chris.
Okay, so that is a change. And notice
that now that your Xcode project is inside of a repo, Xcode actually recognizes that and it puts a little M
beside the file that you changed since the last save. And then if you go to GitHub desktop, it also recognizes that
you've made a change since your last commit. Notice that it also highlights
commit. Notice that it also highlights that line and tells you what you've changed. So again, this is really handy.
changed. So again, this is really handy.
But let's just say that I've just finished this new feature and I want to save my progress by making a commit. So
I will go down here like before and I'm going to say uh update name.
Okay, I'm just going to go ahead and commit it. And by doing that, I have
commit it. And by doing that, I have created the snapshot or commit locally.
You'll notice here that there's this upwards arrow. That means it it has yet
upwards arrow. That means it it has yet to be pushed online to the online repo.
And it tells you these ones are already in the online repo. This one has yet to be. So, I can go ahead. Typically, it
be. So, I can go ahead. Typically, it
goes hand in hand. you commit and then you're going to hit push and it's going to upload that commit to here. And then
if we refresh it from the browser, we can see that there was uh first of all an additional commit because it this was
at two before and then also that there's been a recent change. So if we browse through the online repo and we click into this file, you can see that it contains my change here. Right now let's
say I changed my mind. I want to go backward. Maybe I've ruined my project
backward. Maybe I've ruined my project and it it can't run. So maybe I've done something like this where let's just say I did something like
this. I accidentally erased some code
this. I accidentally erased some code and now my project doesn't build properly and I can't figure out why it's not building and I wish I could hit
undo. Well, first of all, you can you
undo. Well, first of all, you can you can just go to your um GitHub desktop and remember it tracks all the changes
you've done since your last commit. And
if you are only committing at a good stopping point in your project, you can simply just undo all the changes since your last commit. So right here, I've
made a change. If you rightclick this file, you can just discard it.
So discard and then I'm automatically reverted to my last commit. It's a clean slate. I'm back where I started.
slate. I'm back where I started.
This is like restoring your latest save point. But let's say I wanted to go even
point. But let's say I wanted to go even farther back in time. Let's say I've made several commits and then I realized, oh, I made a wrong turn
several commits ago and you want to go back farther. This is how you would do
back farther. This is how you would do that. So, go back to GitHub desktop and
that. So, go back to GitHub desktop and if you go to history, you're going to be seeing your list of commits. And in
order to roll back to a previous commit, you can undo. It's kind of like peeling back the layers of an onion. So, let's
say I wanted to get back to this point.
I would have to roll back this one first. So, I can rightclick it and I can
first. So, I can rightclick it and I can say revert changes and commit. And what
it's done is it's created a set of changes that reverses the changes that I made. So you can see here I've changed
made. So you can see here I've changed hello world to hello Chris. And now it created this new commit for me which is
changing from hello Chris back to hello world. So you can do that for each of
world. So you can do that for each of the commits that you want to um undo and then you can get back to your original state. If I go back to my project right
state. If I go back to my project right now, you're going to see that it's hello world instead of hello Chris. So that's
how you're going to step backwards and get back to an earlier save state, so to speak. So just to recap your two
speak. So just to recap your two options. The first option is if you just
options. The first option is if you just want to restore to your most recent good commit, you can come here and look at the changes that you've done since that
point and just highlight all the files, rightclick and say discard changes. And
that's going to remove all the changes and bring you back to that most recent good commit. And that should be a clean
good commit. And that should be a clean working state. If you need to go back
working state. If you need to go back even further, this is when you go to the history tab and for each change that you want to roll back, you rightclick it and
hit revert changes and commit. It's
going to automatically make a set of changes to counter that commit and then you can roll back as many steps doing that as you would like. So, there are other ways of working with source
control as well and that's what makes this such a great tool, but those are a little more advanced and we're going to cover it in the future. this what you've just learned covers 90% of the basics of
using source control. And if you use it like I've showed you today, you're going to be good. So now that you use GitHub for source control, you'll never have to restart your project from scratch again.
Now, there's one thing we haven't talked about today, and that is the ability to create a copy of your project so that you can experiment and try to build new features on the copy instead of on your
main project. That feature is called
main project. That feature is called branching and it's super useful because it eliminates any possibility of messing up your main project. That is something
we're going to cover in part two right over here. All right, I'll see you
over here. All right, I'll see you
Loading video analysis...