Basic Git Commands (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 »

Time
21 hours 25 minutes
Difficulty
Intermediate
CEU/CPE
21
Video Transcription
00:00
>> Hey there Cybrarians and welcome back to
00:00
the Linux Plus course here at the Cybrary,
00:00
I'm your instructor Rob Goelz.
00:00
In today's lesson, we're going to talk
00:00
about basic Git commands.
00:00
Upon completion of this lesson,
00:00
you are going to be able to connect
00:00
a project to a remote Git repository,
00:00
as well as understand the commands that you're
00:00
going to use most frequently in Git,
00:00
and use the commands Git clone,
00:00
commit, push, and pull.
00:00
A remote repository just provides
00:00
hosting of Git projects
00:00
that we have locally on our system,
00:00
and there are a lot of different options
00:00
to choose from for Git hosting.
00:00
We see a few of those over on the right-hand side.
00:00
Make sure to research
00:00
the different Git hosting providers.
00:00
Most don't charge for basic hosting,
00:00
but if you have large-scale projects,
00:00
they probably will charge for that,
00:00
and some only provide
00:00
public repositories and then charge for private repos.
00:00
If you have information that is
00:00
projects that are large
00:00
or information that you want to be private,
00:00
make sure you research the hosting provider
00:00
and what they actually allow you to do.
00:00
Now in this module, we're going to use
00:00
GitHub and we'll set that up in our demo.
00:00
Once we've established our Git environment
00:00
and we have a remote repository setup,
00:00
we can start using some Git commands.
00:00
There's just a general four-step process
00:00
for using version control with Git.
00:00
First we create and modify program files.
00:00
Two, we go ahead and we add those files to
00:00
a staging area using the git add command.
00:00
Then we do a git commit and we commit
00:00
the files to a local repository with the message,
00:00
and finally we push the files from
00:00
the local repository to
00:00
a remote repository using git push.
00:00
Let's take a look at all of this with some demo time.
00:00
Here we are back in our demo environment,
00:00
and if we haven't set up an account on GitHub yet,
00:00
we can go ahead and do that by clicking on Sign up.
00:00
It'll take us to this page where
00:00
we can put in our username,
00:00
email address and password,
00:00
verify your account and then we'll be all good to go.
00:00
In this case I've already done so,
00:00
I'm just going to go ahead and click on
00:00
Sign in with my account.
00:00
Once you're signed in,
00:00
on the left-hand side,
00:00
you can click on "Create repository."
00:00
Once you've created your first repository,
00:00
you can also see that from up here where
00:00
it shows you new repository.
00:00
I'm just going to create
00:00
this repository and I'm going to call it bash-scripts.
00:00
Then what I can do is I could give it
00:00
a description, I'm not going to bother,
00:00
I'm also going to leave it public because I don't have
00:00
anything too top-secret here.
00:00
I'm just going to go ahead and add a README file,
00:00
and I'll hit Create repository.
00:00
Now we see that this is created,
00:00
it has a README file which is pretty
00:00
blank and nothing else in it.
00:00
Now what we can do is we can get
00:00
this repository clone down to our machine locally.
00:00
I'm just going to highlight this and hit Copy,
00:00
and I'm going to go back over to our Bash shell.
00:00
Now what I'm going to do is I'm
00:00
going to make sure that I'm in
00:00
my user home directory where
00:00
I am, present home directory.
00:00
Present working directory is user home
00:00
in my case home rob,
00:00
and what we're going to do is we're
00:00
going to do a git clone.
00:00
We'll do git clone,
00:00
and we're going to clone
00:00
https://github.com/Goelzindustries/bash-scripts.git,
00:00
and we'll see that that has been done.
00:00
Now if I do an ls in my home directory,
00:00
I see this bash-scripts directory that's there.
00:00
I can do an ls on that or an ls-al on bash-scripts,
00:00
and I can see all the contents of this.
00:00
Right now it just has that.git
00:00
file or.git directory rather,
00:00
which is going to have
00:00
all the version control information
00:00
locally for my system,
00:00
and that README file, which is the only thing that
00:00
we have here so far.
00:00
Let's go ahead and add some
00:00
files into our scripts folder.
00:00
For example, let's copy everything out of bin.
00:00
I'd copy home/rob/binstar,
00:00
and I'm going to copy that into
00:00
home/rob/bash-scripting or bash-scripts rather.
00:00
Oh, sorry, we're going to do
00:00
A copy-r to make sure we get all that information.
00:00
Now if we look at our directory again, if we do an ls,
00:00
we can see that we have inside of bash-scripts,
00:00
we have our bin file and we have the README file.
00:00
Now what we can do is we can go ahead and add all
00:00
that to our staging area by using the git add command.
00:00
First let's navigate into bash-scripts,
00:00
and now let's run the git add command,
00:00
so git add star.
00:00
Now if we run git status,
00:00
we're going to see that we're on branch main
00:00
and our branch is up-to-date with origin/main,
00:00
but we need to do a commit because we have a new file,
00:00
we have something in our bin directory called loops.sh.
00:00
What we can do is we can run a commit.
00:00
All of our files have been stored in
00:00
the index so we need to commit it now.
00:00
We could do git commit-m and
00:00
the general commit we always
00:00
start with is initial commit,
00:00
then I say add existing bash-scripts.
00:00
I'm having a little trouble
00:00
spelling bash, sorry. There we go.
00:00
Now if we run git status,
00:00
we'll see that we're on branch
00:00
main and everything has been committed.
00:00
Nothing to commit, our working tree is clean.
00:00
Great, we're good to go. But what do we do now?
00:00
Now we have stuff on our machine locally that we
00:00
don't have up in our remote repo.
00:00
What we can do is we can run the git push command.
00:00
Now we have to put in our username and password,
00:00
so I'm going to put in instructor@goelzind.com
00:00
and I'll put in the password and hit Enter.
00:00
It's going to go ahead and push
00:00
that information up to GitHub.
00:00
Now if I go back to GitHub
00:00
and I hit Refresh on this page,
00:00
we'll see that we also have the bin directory and
00:00
>> inside this bin directory we have a loops.sh file.
00:00
>> We're good to go. Now, if we want to,
00:00
we can also modify the README file.
00:00
We can modify a file on
00:00
the remote repo for some reason and we can
00:00
get it down to
00:00
the local repo with git pull. Let's do that.
00:00
Let's go back to our bash-scripts here and
00:00
we're going to modify the README file,
00:00
and we're going to see that won't change locally.
00:00
We can go in here and we can just
00:00
change this and we can say,
00:00
bash-scripts made a change.
00:00
Then we can go ahead and down here we can just
00:00
commit these changes directly to the main branch,
00:00
and we see that this change is made.
00:00
Now if we go back down to
00:00
our system and we do an ls on README,
00:00
we see that it just has README.md.
00:00
If we do a less on this,
00:00
we see that it just has that
00:00
bash-scripts at the bottom of it.
00:00
What we can do now is we can do a git pull.
00:00
Now it's going to go ahead and fast
00:00
forward and pull down information.
00:00
If we do a less on README again,
00:00
now we see that it shows that made a change.
00:00
We modify that README and pulled it down locally.
00:00
With that, in this lesson,
00:00
we covered connecting a project
00:00
to a remote Git repository,
00:00
we talked about the commands and processes you
00:00
will use most frequently in Git.
00:00
Then we use the Git commands, git clone,
00:00
git add, git commit,
00:00
git push and git pull.
00:00
Thanks so much for being here and I look
00:00
forward to seeing you in the next lesson.
Up Next