- Git is a version control system
that lets you keep track of the files in a project.
In order to use Git we start by
identifying a folder as a Git repository.
You do that by issuing a Git init command
within a folder.
Let's go ahead and take care of that
and look at some of the basic commands
you'll need to get things going.
So on my desktop I'm going to create a new folder.
I'm going to call it Project.
I'll open this up in my favorite text editor.
I like using Sublime Text.
Open a copy of the Terminal.
Go ahead and clear out the Terminal
so that we start with a clean screen.
In my Project folder I'm going to
create a new file
and I'll call this index.html.
I'll create some basic HTML content in there.
(typing)
I'm gonna save this file and
I'll make a copy of it.
It's already here on this Project folder.
So I'll just make a copy of it by
right-clicking and selecting Duplicate.
You can also do Copy and Paste
if you're on a Mac or a PC.
Now on a PC the Terminal application
would be the Git Bash application.
Do not use the DOS Command prompt
or some of these commands are not gonna work.
So in our about page I'm gonna modify this to say
About, and I'll use a different pangram here.
A pangram is a sentence that uses
all the letters of the alphabet.
So let's say that we want to keep track
of this project using version control.
You can do that by making sure that
in your terminal you're inside this project folder.
So first I need to travel to the
Desktop/project folder using the cd command
in your terminal application, or Git Bash.
Then in there I can issue a Git init command.
This will initialize this folder as a Git repository.
You can tell that this is being tracked by Git
because there's a hidden folder
inside this directory.
You can't see it with your regular operating system
so it's not here.
But if you go to the Terminal and
you issue an ls command or an ls -la command,
you'll see that there is another folder here
called .git.
It's an invisible folder but this is where Git
is going to keep track of everything
going on with your project.
Git has a couple of different places
where you can store the state of files.
One of them is called the staging environment.
We can add anything to the staging environment
by using the command called Git add,
and then the name of the file
that we want to add.
So for example you can say,
Git add index.html
and what that will do is add that file
into our staging environment.
You know that that has happened
because you can do a Git status command,
and take a look at the status of the files.
You can see that there are two files here.
One of them is our new file index.html
that we have added to the Git
staging environment,
and therefore it's ready for something
called committing,
where it's ready to be committed.
And then there's this other file called
about.html that is being listed
as an untracked document.
That means that Git doesn't know anything about it.
It's not going to track it,
and so it's not really part of what Git knows.
You can add individual files to the staging environment.
But really most of the time
you'll want to work on a number of files,
or just add all the files that
you've made changes to.
That command command is called
Git add and then period.
Execute this and we do a Git status command.
You'll notice that now both of those files
are ready to be committed.
As you work through a project you
can keep on adding things to the
staging environment
until you're ready to commit it
to a permanent record.
The Git status command is always
going to show you what is going
with Git at any particular moment.
It shows you what's in the staging queue
or any files that are untracked
by Git at the moment.
Let's say that we're ready to make
a record of where our environment is
at this time.
That is called committing.
Now the difference between staging
and committing is sort of like
saving a file versus printing it.
When you save a file you sort of
save the current state of the document.
However when you print something
it becomes a more permanent record.
More than likely because this is something
that is ready for somebody to look at.
A printed document is much more
serious than just something you
save on your hard drive.
So commit is a record of the state of the folder.
Whatever was in the staging environment
will be locked as a record in the commit log.
So let's go ahead and commit these files.
So we'll say Git commit,
you always do a -m
which allows you to create a message
for this commit.
We'll say this is revision one.
You should get a message like this.
Now when you commit things for
the very first time
you might get a message that looks
something like this.
Now Git is used to tracking projects
for multiple users,
so it's important to let it know
your personal information.
Just go ahead and run these two commands
with your own name and email address.
When you make a commit,
a record of where everything is gets stored.
So that we can always come back to
this point in time.
Now let's go ahead and run a Git status command
to see where we're at.
So it's showing you that we're on a
branch called master.
We'll talk about that in a later video,
but it's saying that there's nothing to commit,
everything is clean.
So there is no files that we've made changes to.
There's actually a record in our log
that shows us where we're at.
So we can look at the log by issuing
the Git log command.
Let me go ahead and clear the screen now,
because it's a little bit better sometimes
when you're working with a lot of commands.
We'll do a Git log command
and you can see that the commit
that we did is right here.
It gets this really weird hash,
and it also gets a name down here
which is what we added as the comment
when we issued the commit -m command.
This is gonna show the first line
of what your commit message was.
The commit message can actually be longer
but all you're going to see here
is just the first line.
Now a log shows the record of all the commits
that we've been making in our project,
so as your project gets more
and more complicated
you're going to see a lot of these
different logs.
Now those are probably the commands
that you'll run most often with any project,
and that's already a lot of commands
to learn in one sitting.
So make sure you take some time
to create projects with Git init,
to take a look at the status,
and add some files into staging
and then commit some files.
Play around with it.
Me talking about it is not going to
teach you all that much.
This is definitely something that you
want to try out yourself.