Git is a version control system
Git is a version control system
In its simplest form, version control is saving a series of changed files on a computer, for example, with different dates in the name, or a revision tracking mode in text documents.
Developers often need to revert to a previous version of their code:
- if it turns out that the problem being solved is no longer relevant;
- if you need to make corrections to an earlier version of the program;
- if an error was found while working on a new task.
- If there are many people working on a project, you want them to be able to make changes to the same files
- without conflicts and code loss. All these tasks are conveniently solved using Git.
The core features of Git include:
- return to any previous version of the code;
- viewing the history of changes;
- parallel work on the project;
- backup code.
Getting started with Git
To work with Git, you need to install it on your computer. On the official Git website, you can find an installer and detailed instructions for beginners.
Git can be used from the command line in the built-in terminal, or you can install a client with a graphical user interface. The graphical interface is more convenient for beginners, however, often such clients have only some of the functionality implemented, so developers mainly use the command line.
What is a Git repository?
A repository is all files under version control, along with their change history and other service information.
You can create a Git repository either by selecting any folder on your computer, or by cloning yourself an existing repository, for example, from an employer.
Where is the repository stored?
There are different ways to store and use the repository: there are local, centralized and distributed version control systems.
In local version control systems, the repository is stored and used on one device, but only one developer can work with such a system. In the case of a centralized system, the repository is stored on a single server.
Distributed version control systems, which include Git, are best suited for a large number of developers. Such a system is a cloud storage: each user stores the entire repository on his device, and as changes are made, the repositories are synchronized.
What is commit and commit?
In English commit means “fix”. A git commit is an operation that takes all prepared changes and commits them to the repository as a whole.
Why do we need a commit if Git is already keeping track of all the changes? Commits break the development process, which consists of a large number of edits, into separate steps. That is, a commit is a kind of logically complete change within the project and a point that is understandable (including to other developers) to which you can return if any problems arise.
Changes within a single commit are subject to certain rules and guidelines established by the development team regarding the naming, description, and content of commits.
As a rule, the workflow is a cycle: commit – change files – commit.
What is branching?
Convenient branching support is an important feature of Git. Using branching allows you to solve individual problems without interfering with the main development line.
A branch in Git is a series of commits. Technically, a branch is a pointer or link to the latest commit in that branch. By default, the master branch name in Git is master. Each time a new commit is created, the master branch pointer is automatically moved to it.
When a new branch is created, the commit is given a new pointer, such as testing. If you switch to the testing branch and make a new commit, the pointer to the testing branch will move forward, while the pointer to the master branch will remain in place. By switching back to the master branch, the files in the working directory will return to the commit state pointed to by master.
Why is GitHub needed?
GitHub is the most popular site for hosting and working with git repositories. GitHub is also the largest platform for hosting open source projects. No registration or account fees are required to view and download public repositories.
In a sense, GitHub is also a social network for developers. Registered users can publish content and manage their own repositories, contribute to other people’s repositories, conduct discussions, view code changes, comment on them, and follow updates from friends.
GitHub is often used in recruitment – an active account and high quality code can greatly help in finding a job. Therefore, it is especially important to have an account to show your code to colleagues and how it evolves over time.
There are now many other online services that are integrated with Git. Alternatives to GitHub are, for example, GitLab and BitBucket. Both sites have a smaller audience, but they have their own functionality and their own advantages, for example, BitBucket is more convenient for small closed source projects.