git course

The Git course begins with this first class, in which we give an introduction to the most important Git commands and explain what the GitHub service consists of.

We are going to get to know the main Git commands through a practice in which we will try to illustrate how the tool is used to manage the versions of a project. The goal is to see how a repository is created, how the repository files are updated, and how we can go back to recover the state of the files in previous versions of development.

Later, we will see how a repository can be created on Github and how we can send the changes from our local Git repository to Github, all in the space of just over an hour of class.

In the video we always work with the terminal, entering the commands by hand. Although there are various programs with a graphical interface that can also make things easier for you, the only way to exploit all the possibilities of Git is through the command line.

Installing Git

In the video we spend a few moments mentioning the main ways to install Git on a local computer, to have the terminal where we can launch the Git commands. It is very easy to install, obtaining the download from its official page:

On Windows the download is an executable that you can install normally. On Mac you can also install it through the file you download, as well as download it using Home Brew. In Linux you can find it in all the repositories of the main distributions, whose packages you install with Apt-get, Yum, etc.

Note: With the Windows version of Git you can’t run Git commands directly from the Windows console, instead you have to use Git Bash, which you get when you install the tool.

We don’t have to be afraid of using the command console, but if we want we can use visual tools, of which there are a lot, as well as Git can be integrated into most IDEs and even through plugins in code editors like Sublime Text.

Creating a local repository

It’s as simple as going to a directory on our machine from the command line or from Git Bash, if you’re on Windows. We start with an empty directory, since we are supposed to start our project and then we can run the command: git init

From then on you have a whole complete software repository on your machine from the project you had in that directory. You can create the files you want in the directory (your project) and then you can commit them to the repository.

Note: The big difference between Git and other repositories is that it is distributed. All repositories on each machine are complete, so that machine could perfectly stand alone and develop code anywhere in the project. That’s why I can commit to the local repository, regardless of whether the computer is connected to a network or not.

In the video we know several additional commands such as “status”, “log”, etc.

Add files to the repository

Before committing changes to the repository, which is known as committing, you have to commit the files to an intermediate area called the “staging area” where the files that would be updated in the next commit are stored. This is one of the essential concepts to learn Git and to send the files to this area we have to add them to the repository.

git add .

With this command I pass the files to the “staging area”. In this case “git add .” allows you to send all changes to the working directory, including new files and files that have been modified.

Once the files have been added to the staging area, we can now commit those files.

git commit -m “this is my first commit”

This command allows you to send the files to a kind of database where you can place the files whose status we always want to memorize.

Here in the video we briefly talk about branches and how they are managed in Git and we mention that the main branch, which is created when the repository is started; is called “master”. We also see how to locate commits through their identifier, which helps us to move between software updates.

Every time a file is modified, you have to add it to the staging area with the “add” command and then commit it so that the repository is updated with the new or updated files. That means that in theory every time you change a file you would have to add it to the Staging area to be able to commit, although later we will see that there are ways to automate the tasks a bit more and, through shortcuts, to be able to summarize the step of doing the ” add” when the code of a file has been changed.

Undo changes

At any time I can undo changes I have made to the files, bringing back previous versions that we may have in the repository. I could discard the changes I have in the staging area.

git checkout — file_name

In Git you can have code mainly in three places, the working directory, in the Staging area or in a version that you have in an old commit of that repository. There are different commands to do all these things, depending on where in Git you have the code you want to retrieve. But the really useful and powerful thing we have with version control is being able to recover files made in previous commits, in the last commit, but also in others that you have older.

There are many commands to recover previous code such as “reset”, in the video you can see several examples, it also explains how to merge commits and many other interesting things.

Github

The video then shows how to work with Github, showing the possibilities of this remote repository storage service. We see how a repository is created in Git and how it can be cloned to our local system.

To work with Github we have some important features such as SSH security keys, which we have to generate locally and take to Github to give an additional level of security to the updates against the repositories.

The video shows how the repository is created on Github and how it is cloned locally using the “clone” command. Once cloned, it shows how the files are updated locally, they are added to the intermediate area with “add” and the “commit” is made to the repository locally. Finally, the changes are sent to the remote server with “push”.

All this is not an immediate step, but the video explains it fantastically.

git course

All the material seen in the video is just the tip of the iceberg, that is, a small sample of all the enormous possibilities of Git. This one-hour class will surely help you get started with Git, but there is much more behind this tool. There are still many things to see and fundamental concepts such as “fork”, “pull”, “merge”, “checkout”, “fetch”, “branch”…

We will see all this material in detail in the EscuelaIT Git Course, throughout ten hours of live classes that will be held for a little over a week. This video is just a small sample of the content that will be seen there in full detail.

You can get more information from the .

For now we leave you with the video that we hope you can enjoy a lot!

See also  Laravel Handbook
Loading Facebook Comments ...
Loading Disqus Comments ...