- Let's talk about Git.
Git is a distributed version control system.
It allows developers to work in products together,
where each file revision is stored in the system.
Old versions of files are always available,
and the log is maintained
of who made what change to which file.
Git is distributed
because it allows developers to work offline
after cloning a remote repository locally,
and that makes it a very popular platform.
Git works with a repository,
which can contain different development branches.
Developers and users can easily upload as well
as download new files to and from the Git repository,
and in order to do so, a Git client is needed.
Git clients are available for all operating system.
No matter if you work on Windows, Mac, or Linux,
you'll find a Git client.
At the other end there's the Git platform.
GitHub is a very common platform,
GitLab is a common alternative,
and private Git servers can also be hosted.
In this lesson, I'll be focusing on GitHub,
because it's the most common platform
and all Linux development is mainly happening on GitHub.
To work with Git successfully,
It helps if you understand the Git workflow.
After cloning, the developer makes changes
to the working tree.
All changes are made to the local repository,
and developers can push changes to the remote repository.
And if the local repository is network accessible,
the owner of the repository can even pull changes from it,
but that's pretty uncommon.
Normally the push is developer initiated.
Now in Git, there are these different trees.
The Git repository has three trees in total
and these trees are stored as files
in the .git directory on the developer workstation.
The working directory holds the actual files,
the index acts as a staging area
and the HEAD points to the last commit that was made.
We're working with Git,
the git add command is used to add files to the index.
I'll show you all about that,
but first I want to give you the overview.
So git add is the first step.
Next, you are going to commit the files
that you have just added
to the HEAD using git commit followed by a commit message.
This commit message is also published on the Git website,
so it's pretty important to make a clear message
so the users can see what exactly has changed.
Now, in order to connect
to a remote repository from the client,
you need git add origin
and that will make the connection for you.
And on the Git client,
you identify this Git remote repository next
by using git remote add origin,
where origin is the identifier
for the Git repository, it can be anything.
Instead of origin, you will also find main
and master for instance.
So to complete the sequence, you use git push origin main,
and there you replace the name main
with your actual branch that you want to push changes to.
Alright, let's try to understand the Git procedure.
So it all starts on the Git server
and from the get server,
you are going to use git clone command.
And this get clone command
or git pull command comes down to the same.
That makes that you have your files
on what we will call the Git client.
Now, from the Git client,
you are going to work with your files.
So we call it the working directory
and that is where you are going to add your files.
So, in the working directory, you apply your changes,
and these changes need to be added using git add.
Now, while working with Git, your files
and these files can be in different states.
You can use git status
to figure out what the actual state is.
So the three states are modified.
So modified is what you get
if the file in the working tree is different
from the file in the repository.
Staged is where the modified file was added
to a list of changed files in the index.
And committed is where the modified file has been committed
to the HEAD and is ready to be pushed.
After committing a file to the local repository,
it can be pushed to the remote repository.
Now that we know a little bit
in general about the working of Git,
let's further explore and let's talk about authentication.