Git - what is it? Git for beginners: description

Many software developers have heard of Git. What are these three letters? It is very important to understand the description, as well as the principles of functioning, in order to effectively use this version control system in which, unlike other similar systems, completely different concepts about information, work with it, despite the similar user interface. So what is git?

Description

git what is

Git is a distributed system for managing versions of developed files. It was created in 2005 by the author of the Linux OS. This system synchronizes the work with the site, and also saves and updates changes to files. This is a very convenient approach in the case of several developers working on a project. Today, many well-known projects use exactly Git. What does use give? For example, a large number of programmers are developing the Android operating system. It would be extremely inconvenient if one of them made changes, while the others did not know about it. Git allows everyone to keep abreast of all changes, and in case of errors, return to previous versions of files.

Using casts rather than patches

what is git

The main difference between Git and other version control systems is the way it looks at the data. Most programs store information in the form of a list of changes called patches for files. Such systems relate to stored data as a set of files, as well as a set of changes that are made for each file, relative to time. How does Git store its data? What is this system that distinguishes it from others? Instead of patches, the stored data here is considered a set of nuggets of a small file system. Whenever a user commits a new version of a project, the system simply saves a snapshot of the state of the files for the moment. To increase efficiency in the case when the file was not changed, the system does not save it, but makes a link to a previously saved instance in which the latest changes were made.

This is a very important difference from other control systems, which is inherent in Git. What is the difference? Git becomes like a small file system with very powerful tools that work on top of it.

Mostly local operations

git windows

In order to perform most operations in Git, you need only local resources and files. This means that most often there is no need for information on other computers in the network. Since all project changes are on disk, operations are performed at lightning speed. For example, in order to view the history of a project, it does not need to be downloaded from the server. It is read from the local repository on the computer. If you need to see the changes between the version of the file that was made a month ago and the current one, you can do it very quickly without having to go to the server.

Local work also means that you can do a lot of things without connecting to the network. For example, a developer can make changes while in transport. In many control systems, this is not possible.

Data Integrity Monitoring

Before saving any file, it is assigned an index in the form of a checksum calculated directly by Git. What is a checksum? This value, which is calculated using special algorithms and is used to verify the integrity of data during their storage and transmission. It is impossible to change anything here without the knowledge of Git, and this is an important component of the philosophy of the system.

Data is most often added.

git remove

Almost all actions performed in Git are added to the database. Removing them is very difficult. You can only lose information that has not yet been saved, but when it is committed, loss is excluded. For this reason, many people choose Git, because here you can conduct experiments without risks to do something irreparable.

File Status

Working with Git for beginners involves remembering that a file can be in one of three states:

  • Committed, that is, the file is saved in local storage.
  • Modified when edits were made, but the save has not yet been completed.
  • Prepared - modified files that are marked for saving.

So, in projects that use Git, there are three sections for different file states:

  • The Git directory where metadata is stored, as well as a database of objects. This part of the system is the most important.
  • The working directory, which is a copy of some version of the project extracted from the database.
  • A file containing information about subsequent save.

Install Git

initial git setup

The first thing to do in order to use the version control system is to install it. There are several ways to do this. The main ones are two options:

  • Install Git from source.
  • Installing the package for your platform.

Install Git from source

If this is possible, it is better to use this option, since the latest version will be received. Each update usually contains many useful improvements regarding the user interface. That is why, if installing from source is not too difficult for you, it is better to prefer it. Yes, and most Linux distributions include legacy packages.

To install, you will need the necessary libraries: expat, curl, libiconv, openssl, zlib. After installing them, you can download the latest version control system, compile and install it.

Windows installation

If the user does not have Linux, but wants to use Git, Windows also supports this system. And installing it is very simple. There is a msysGit project, the installation procedure of which is one of the simplest. You just need to download the installer file, which can be found on the project page in GitHub, and then run it. At the end of the installation, there will be two versions on the computer - graphical and console.

Git initial setup

git for dummies

After the control system is installed on the computer, you need to perform some actions to configure the environment for the user. This is done once. When updating, all settings are saved. They can be changed at any time.

Git includes the git config utility, which allows you to make settings and control the operation of the system, as well as the appearance. These parameters can be stored in three places:

  • In a file containing values ​​that are common to all users and repositories.
  • In a file containing the settings of a specific user.
  • In the configuration file located in the current repository. Such parameters are valid only for him.

Username

First of all, after installation, you must specify the username, as well as email. This is very important, as each commit (state preservation) contains this data. They are included in all committed commits and cannot be changed subsequently.

If you specify the –global option, such settings will need to be done once.

Choosing a text editor

After specifying the name, you need to select the editor that will be needed when typing messages in Git. By default, the standard operating system editor will be used. If the user wants to use another, you need to register this in the configuration file settings in the line core.editor.

Verification of parameters

To know the basics of Git, you need to be able to check the settings used. To do this, use the git config –list command. It displays all the available parameters that it can find. Some setting names may appear on the list more than once. This is because Git reads one key from different files. In this situation, the last value is used for each key. It is possible to check the values ​​of certain keys by entering in the command instead of “--list” - “{key}”.

How to create a repository

There are two ways to achieve this goal. The first is to import an existing catalog or project into the system. The second is cloning an existing repository from the server.

Creation in this directory

If the user decides to start using Git for an existing project, he must go to the directory and initialize the system. This requires the git init command . It creates a subdirectory in the directory where all the necessary files will be located. At this stage, version control of the project has not yet been established. To add files under control, you need to index them and make the first commit changes.

Repository Cloning

To get a copy of an existing repository, you need the git clone command. With it, Git will get a copy of almost all the data from the server. This applies to all versions of each file. This is a very convenient feature, since in the event of a server failure, the programmer will be able to use the clone on any client to return the server to the state it was in when the clone was located. It looks like a recovery point.

Delete a file in Git

You can delete any file from the system if you exclude it from the index, that is, from monitored files. To do this, you need the git rm command. It also removes the file from the user's working directory. Then you need to commit. After it, the file simply disappears and will no longer be tracked. If it is changed and already indexed, then forced deletion with the -f option is used. This method will prevent the deletion of data that has not yet been written to the snapshot and which cannot be restored from the system.

Revert Changes

At any time, you may need to cancel an action. If the user executed the commit early, forgetting to add some files, then you can overfulfill it using the --amend option. This command is used to commit the index. If after making the last save no changes were made, the project will be in the same state and an editor for comments will appear, where the user can edit everything that is needed. It must be remembered that not every cancellation operation can be undone. Sometimes you can permanently delete the necessary data. Should be careful.

Summary

working with git for beginners

Now the user should have an idea of ​​what Git is, why this version control system is needed, how it differs from other similar products. It is clear that for a complete familiarization you need to install a working version of Git with personal settings for yourself. Any textbook or video course on Git for "dummies" that can step-by-step guide the user through all stages of working with the system will not hurt.

Source: https://habr.com/ru/post/K17285/


All Articles