- [Cameron] Hey, I'm Cameron McKenzie.
I'm the editor-in-chief at TheServerSide.com
and I wanted to talk to you a little bit about
the Git working tree,
and how the Git working tree works
in terms of adding files,
deleting files, updating files,
and even inspecting what's going on
in that Git working tree
with the git status command.
I've created a folder here, it's _bart.
As you can see,
there's no Git or even file activity in there,
but that's what I want to make my workspace.
This is where I want to put all of my code for development.
So if you want to do that,
I guess the first thing you want to do
is initialize that repository as a Git repository.
So I opened up my Git Bash here
and I'll just do a little init command.
As soon as I do that,
you'll notice that a handsome little
.git directory appears there.
It's kind of shaded 'cause it's a hidden directory.
That's not part of what you would call the Git working tree.
Those are kind of part of the plumbing files for Git,
but any of the files that I create in this area
would be considered part of the working tree.
One way to get insight into your working tree
is to use the git status command.
And so right now I'll say,
"Hey, give me some status, Git."
And then it'll say I'm on the branch master,
there's been no commits,
and really there's nothing of interest on there.
So why not create a new page,
a new file?
I'm gonna do that using the touch command.
Create a file called home.html.
You'll see that file appears magically there
after using the touch command,
and why don't I issue the git status command again?
I notice here it says,
"Hey, on this working tree in your workspace,
in the Git working tree,
there's a file there named home.html
and it's currently untracked."
Now, there's a reason why I called it home.html.
You would think that the first file you create
would be called index.html,
but the reason why I called it home.html
is 'cause there's something special called the index
which keeps track of all the files
that should be part of the next commit.
And right now,
I haven't added home.html to the index.
You can almost think of the file system
when you work with Git
as this multidimensional entity.
There's the files that you see
on the current working tree
that are on the current file system in your workspace,
and then Git also has this sort of shadow file system
that is called the index which has all the files
that should be part of the next commit.
And I can always say git add
home.html and then do a git status command,
and you'll notice that it says,
"Hey, there's been no commits yet,"
but this file has been turned from red to green,
and turning red to green basically means
this file is now being tracked by the index.
If somebody actually does a commit,
that file will become part of the next commit.
And so, why not do a commit?
Git commit -m
my first commit.
All of a sudden that file has now been committed
and if I do a git status,
well, the git status is gonna say
you're on the branch master
and there's nothing to commit because nothing's changed
since your last commit.
So why don't we change something?
I may as well add something to home.html.
Let's see, I think I can do, like,
a echo
hello world
and say send that output to home.html.
And then do a git status command
and you'll notice it says,
"Hey, somebody's changed home.html."
And of course, if I bring up home.html,
you will see that it actually says
hello world there, right?
I mean, that file has indeed been changed.
And even if I actually go in here and edit it in Notepad,
you can actually see right there, yeah,
content of that file is hello world.
So that file has now been changed
and indeed it indicates that right now.
So it now says, "Hey, this file has been modified."
And so, I can again add that.
You can use the dot command there.
You don't have to specify the file explicitly.
Then I can say git commit
my second commit,
and then if I do a git status command again,
all of a sudden it says on branch master,
nothing to commit.
So we see kind of new file,
file about to be added to the index,
one that's modified.
Now, one of the questions is what happens
if you remove a file?
Look at that, the file's been removed using the rm command,
and what happens now?
It says, "Okay, this file has been deleted."
If I do a git add
and then get commit,
then it takes me back to my original state.
I can do a git reflog
and you can see the history of commits there,
and you can even see the clean status
on my current working tree.
Anyways, that's sort of how the working tree exists.
It's really about all of the files that are there
inside of what you could consider your workspace,
but not including those hidden plumbing files
in the hidden .git folder there.
And it's just a way of creating files,
Git keeps track of those files that are there,
and if you really want insights into kind of
what the status of the files are on your file system,
whether something's been modified,
deleted, added,
whether something's tracked or untracked,
the git status command is your window
into the workings of the Git working tree.
And there you go, that's everything you need to know
about the Git working tree.
Anyways, why don't you head over to TheServerSide.com?
I'm the editor-in-chief over there.
We've got lots of great tutorials on Git,
GitHub, DevOps, enterprise software development.
If you're interested in my personal antics,
follow me on Twitter @cameronmcnz
and also subscribe on YouTube.