Git Initialization (Demo)

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Difficulty
Intermediate
Video Transcription
00:00
>> Hey there Cybrerians and welcome back to
00:00
the Linux plus course here at Cybrary.
00:00
I'm your instructor Rob Gels.
00:00
In today's lesson we're going to be
00:00
talking about Git Initialization.
00:00
Upon completion of today's lesson,
00:00
you are going to be able to understand the purpose of
00:00
git initialization as well as perform
00:00
an initialization using git init and then
00:00
understand the purpose of
00:00
the gitignore file and git directory.
00:00
If we want to create a new project with git,
00:00
the command we're going to want to use
00:00
is the git init command.
00:00
This is because it initializes the new project
00:00
with git and creates a .git directory.
00:00
When we do git init,
00:00
we're creating that .git directory and that
00:00
holds the version control files locally on our system.
00:00
Now once we've initialized a local repository,
00:00
we might want to add options.
00:00
We saw in the previous lesson
00:00
how to use git config to set up
00:00
things like a global username
00:00
or global user e-mail address.
00:00
But we can also use git config to set up other things.
00:00
For example, we can set
00:00
the default editor with gitconfig --global core.editor,
00:00
and then specify an editor name.
00:00
This case I specified vi.
00:00
Now, while we're using git,
00:00
we sometimes find that
00:00
some unwanted files creep into our repositories.
00:00
Or maybe we have files that we want to exclude,
00:00
git is going to grab everything
00:00
in a directory if we tell it to.
00:00
We need to exclude files that
00:00
we don't want it to pick up.
00:00
Another local configuration option
00:00
can help us to prevent this.
00:00
That's called the.gitignore file.
00:00
The.gitignore file is placed
00:00
in the root of the project folder,
00:00
the one that you just initialized.
00:00
In this file you place the names and directories of
00:00
any files or directories
00:00
>> you don't want git to recognize.
00:00
>> You also need to include the .gitignore
00:00
file in the gitignore file,
00:00
so that git ignores that as well.
00:00
Let's take a look at all of this with some demo time.
00:00
Here we are back in a bunch of environment.
00:00
What we're going to do is perform a git init,
00:00
get some configuration, and then
00:00
maybe add a gitignore file.
00:00
First of all, let's go ahead and
00:00
create a directory for all of our scripts.
00:00
We'll call this one home rob scripts.
00:00
This could be in my home directory,
00:00
and now let's go ahead and navigate into this.
00:00
We'll go to cd home, rob scripts.
00:00
Inside of our scripts,
00:00
sorry, there's a plural there.
00:00
Then inside of this directory,
00:00
we're going to run a git init.
00:00
So I run git init.
00:00
Now we'll see a message that we've initialized
00:00
an empty repository here and empty git repository.
00:00
Now if we do an ls-al in this directory,
00:00
we can see that we have this .gitdirectory.
00:00
Now we can also do an ls-al on .git.
00:00
Inside of here we can see
00:00
all of the version control information,
00:00
things like branches, hooks,
00:00
infill objects and references.
00:00
We'll get into some more information about
00:00
that later in this module.
00:00
But let's add a few more local config options.
00:00
For example, we can do a git config and we can
00:00
add a globalcore.editor as vim.
00:00
Maybe we'll go ahead and play around with autocorrect.
00:00
We'll say git config global help.autocorrect.
00:00
>> We'll change this to 100.
00:00
>> Now if we do another git config-l,
00:00
then there's too many Gs and config.
00:00
If you do it in the git config-l,
00:00
we can see that we have core editors vim
00:00
and help that autocorrect is 100.
00:00
Finally, let's go ahead and add a gitignore file.
00:00
What we can do is we can do vim.gitignore.
00:00
[NOISE]
00:00
>> Inside of this file we'll add a couple of things.
00:00
>> For one thing we can add any file that has a tilde,
00:00
which is a temporary file.
00:00
We can also add star.swap to ignore any swap files,
00:00
and we'll add star.back to ignore backup files.
00:00
Then finally, we also had our .gitignore file
00:00
here to ensure that that doesn't get picked up as well.
00:00
Then we can hit escape:wq, and we're good to go.
00:00
Now if we do an ls in this directory again and ls-al,
00:00
we see that we have git and our gitignore file.
00:00
With that, we've reached into this lesson
00:00
and in this lesson we covered the purpose of
00:00
git initialization as well
00:00
as initializing a project using
00:00
git init and then the purpose
00:00
of the git and gitignore files.
00:00
Thanks so much for being here and I look
00:00
forward to seeing you in the next lesson.
Up Next
Basic Git Commands (Demo)
Advanced Git Commands
Module 27 Overview: Orchestration Processes and Concepts
Orchestration and Monitoring
Orchestration Procedures, Attributes and Inventory