Introduction to Git in 5 minutes

Git is a distributed version control system. This technology is rarely seen in hobbyist practice or study, but having a note of possession, at least at a basic level, on Jun’s resume is a powerful argument in favor of it.

I’ll make a reservation right away: there is already an article on Habré and it is as complete as possible, and therefore long. I will try to outline the very basics in the shortest possible format.

So, let’s begin:

Point 1: “What is this beast and what does it give us?”

Git allows several project participants to work on code simultaneously and to have the most current version of it all the time. It also makes it possible to track who, when and what changes were made in the project.

In addition, this technology allows you to make a branching project structure. As a rule, the head branch of the project is never directly edited, and each developer (as an option, the group) has a personal branch, which is subsequently merged into the main branch.

I see no point in describing the installation or configuration of Git, because there are already many guides, instructions, etc. on this topic. Therefore, we proceed directly to using the installed version.

Point 2: “How can I use it at all?”

Personally, I use the console version as I’m used to it. Therefore, I will write about it, but if you figure it out, then it will not be difficult for you to figure it out in the GUI version.

The first (and most important) command you need to know:

git help

Something seems to me that it does not need introduction, but just in case I will make a reservation that it displays a list of all commands with a short description.

To get help for a specific command, you must enter it after git help, that is, the command

git help push

opens a page with full information in the browser on command push

To create a local repository, the following bunch of commands are used:

cd <путь в вашу рабочую папку>

git init

Connecting to a remote repository is more complicated. Let’s look at the GitHub case for example. The command syntax is as follows:

git clone <адрес репозитория>

You can get the repository address by clicking the big green Code button directly on the repository page on GitaHub.

To update all branches of the repository immediately use:

git pull

And if necessary, update a specific branch:

git pull origin <название ветки>

A branch is created by the command:

git branch <название ветки>

To switch between them, use:

git checkout <название ветки>

Great, now you know how to connect to the repository, create a branch, load the current version of the repository. It remains to figure out how to load your own code into it.

This requires that you are in the project folder. If this is not the case, then fix it:

cd <путь в вашу рабочую папку>

Next, we prepare the content for the commit command:

git add .

The “.” in this case means that we are adding all the contents of the folder.

Finally, we create a commit:

git commit -m "<обязательно комментарий>"

Important caveat: commit it is not necessary to carry out after each written line of code, but only if:

  • you added a new feature

  • you fixed the error

  • you end the work day and want to save the code

Item 3: Conclusion

In this article, I tried to convey the main part of the practical side of Git. For a more complete introduction, I leave links to the article mentioned above:

I would be glad to any constructive criticism. Thanks for reading.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *