Git is a distributive version control system and is now the most commonly used tool by programmers in the development of applications, webs, software, computer systems and more.
But they wonder, how does it work? And what makes it so useful?
Suppose you have stored in your machine a folder of special importance, which we will call the project. This project can contain one or more files of any type (for example, the source code of an application, a book, a research report, etc.). Each time a change is made to the project (such as adding, deleting or editing a file contained in the project) a new version of the project is generated.
A Version Control System allows you to manage the history of versions generated in a given project, so that it can be consulted, as well as to restore the project to an earlier version (for example, when introducing errors in an application). The set of generated versions is known as the project repository.
Among its main characteristics are the following:
-It allows various methods of development.
-Efficient branching system.
-Does not require a permanent connection to the Internet.
– It is relatively easy to install in major OS.
-Have a lot of configurations available.
– Allows sharing of repositories through various protocols.
-Allows the use of aliases for commands.
-Your code is available for any desired modification.
There are graphical (GUI) and command line interface (CLI) interfaces for Git; However throughout the book will be used, mainly because the graphical interfaces are much slower, and Git commands are not so complicated; In short, it is generally more efficient to work with Git from CLI. In fact, the Git installation for Windows contains the bash command line.
Git is available in major OS (Operating Systems). On the official site of Git there is a guide on this in https:\/\/git-scm.com\/book\/en\/v2\/Getting-Started-Installing-Git 2 .
Already having git installed and before starting a project you must make the initial configuration.
To do this, use the git config command, which has the following syntax:
git config [alcance]
The first thing is to say our name and our mail, so that the changes we make are related to us.
git config --global user.name “Name”
git config --global user.email email@example.com
This will store the data in the user’s configuration, to store them in the system configuration or in the repository, simply replace the -global with -system or -local respectively.
Main commands in git
Start an empty repository in a specific folder.
Add a specific file.
git add “file-name”
Add all files in the directory
git add .
Confirm your changes. The “message” is usually used to associate the commit with a brief description of the changes made.
git commit –m “message”
Revert the commit identified by “hash_commit”
git revert “hash_commit"
Upload the branch “branch_name” to the remote server.
git push origin “branch name”
Show the current state of the branch, as the changes that are without commit.
Check the history of commits or modifications
Download a copy of an existing repository
git clone link
Create new branch
git branch <branch name>
Move between branches and upload changes in these
git checkout <branch name>
git checkout <father-branch>
git merge <child-branch>
git pull link
To download changes made in the repository by other users and update local repository:
git fetch origin
git merge origin/master
GitHub is an online platform for hosting projects using the Git version control system. The code is stored publicly, although it can also be done privately, by creating a payment account.
That git is distributed means that it is prepared to be able to work in distributed teams (that is, everyone in your house) efficiently. Imagine two users, one in Spain and another in Russia How do they coordinate? How do you know which code did one or the other and vice versa?
This git problem solves it with a few complicated tools to configure if you do not have the right experience and knowledge (SSH servers, public and private keys, etc). If you are a system administrator and you have your own server, it would not take long to do so. Otherwise, Github gives you all the infrastructure to work on distributed computers through a more comfortable web interface.
Am I interested in using github if I work alone? Of course, for the simple reason that if you have a copy of your source code in github, you have a backup of the entire project. This backup includes not only the code you have now but also all the history of modifications that the code has suffered from the first day. This copy can be recovered at any time and continue working from any computer as if nothing.
As github excise other similar ones like gitlab, Bitbucket and others.
In short git is a very useful and diversified tool for developers, adapted to the needs of today, with multiple benefits in the development of projects.