Project Technical Lead
Git, GitHub and GitLab: What are their benefits?
Git and GitHub are services you’re bound to encounter when programming. Over the years, Git has become the global standard for version control, used by millions of people. But what does this mean in practice and what benefits can this service bring you?
What is Git?
Git is a distributed version control system that tracks changes in any set of computer files. It is typically used to coordinate work among several developers working on the development of some software. Git zaisťuje vývojárom rýchlosť, jednoduchú prácu a podporu distribuovaných, nelineárnych pracovných tokov.
The fact that Git is a distributed system means that a clone of the project represents a complete version control repository. Git facilitates work not only for developers who are located in one place but also for those who work remotely.
Developers synchronize their copy with the server copy after each modification, ensuring that it will be available to other team members working on the project. Other developers can also track the complete history and other stored versions.
The popularity of Git has been growing in recent years mainly due to the flexibility it provides. In addition, it is popular due to the fact that it is free and open-source software distributed under the GPL-2.0 license.
History of Git
The history of Git dates back to 2005. During this period, many developers stopped using BitKeeper, which had been popular since 2002. This was mainly due to copyright issues.
One of the developers, Linus Torvalds, was looking for a distributed system that he could use just like BitKeeper. However, none of the available free systems met his needs.
Torvalds had precise requirements that the system had to meet. One of them was that a fix should take no more than three seconds within the system, and the system should support a workflow similar to BitKeeper’s.
Since none of the software he found met Torvalds’ requirements, he decided to write his own. The development of Git started 3. april 2005, with the first testing having already taken place on 29. april 2005.
After testing Git, Torvalds handed over maintenance of Git to Jun Haman, the project’s main contributor, who was subsequently responsible for the release of version 1.0. It saw the light of day on 21. december 2005.
Git basics
Whenever you use Git and save any changes, the system creates a commit. A confirmation is a snapshot of all files at a given time. Each confirmation creates links to the next confirmation, creating a clear and handy chart of the development history.
Thanks to the development history, you can go back to a previous version at any time to check it and see, for example, where a bug occurred.
Branches in Git
Git works on the basis of so-called branches. Each developer has its own branch, or code repository, outside of the main one. Once the work in the branch is complete, you can merge it back into the main branch or directly into the trunk.
Files in Git
In addition to branches, it is also important to know about files, which can be in one of three states, namely:
- changed,
- phased,
- confirmed.
In the case of the first state, the changes are found in the working directory. They are not part of the confirmation or development history. However, in order to get them into history, the developer has to phase them.
When the developer is satisfied with his work and phasing, he can include everything in the last phase, which is confirmation. The confirmation then becomes part of history.
Changes in Git
Git differs from many other systems, such as CVS, Subversion or Perforce, in the way it looks at data. Most systems store individual information as change lists. For them, it is just a set of several files and changes at a certain time.
Within Git, however, it’s different. It looks at data as a collection of snapshots that are part of a system, or a file. Every time you confirm and save something in the system, it takes a photography or screenshot of what the files look like at a certain time.
Git then saves a reference to the snapshot and does not re-save the file if it is unchanged after further work is done. Refers to a previous identical file.
In practice, this means that Git checks every single version you make, unlike other systems that just copy previous versions.
Local work
Interestingly, Git mainly uses local files and resources to do its work. It does not need information from other places, such as other computers. In other words, your entire project history is stored on your local disk, making changes and modifications instantaneous.
So if you decide you want to see a version of a project from a month or two ago, Git will load it for you in seconds. It doesn’t have to download individual pieces of data from a remote server.
The fact that Git works largely offline has other advantages. You don’t need an internet connection to make changes or work on your project. So you can do your work wherever you are, whether you’re on a train or in a café where you don’t want to use public Wi-Fi.
Why use Git?
Several developers are currently working on most of the projects in parallel. In order to be able to adapt to each other’s work, or to avoid doing the same thing or unnecessary conflicts in the code, it is important that they use a version control system.
However, in addition to a version control system, you also need a version control system that allows you to track individual changes and revert to an earlier version of the code. All this and much more can be provided by the handy Git tool, which is free and fast.
Other advantages of this system include:
- Strong community support – because Git is open-source, it is used by a large number of people around the world. They discuss and answer questions together in various forums and Facebook groups. So if there’s anything you’re unclear about, don’t be afraid to ask them.
- Simplicity – using Git is not difficult and is often part of programming for beginners. Studying the procedures and how to use the system to your advantage is facilitated by the wealth of information available on the internet. Along with expert articles, you can watch freely available videos or read various books for more information.
- Concurrent development – thanks to Git, each developer can have their own copy of the project they are working on.
- Flexibility – by supporting parallel work on a single project, Git provides a high level of flexibility for your entire team.
- Change Request – Many developers also appreciate Change Request, which allows them to discuss code changes with the entire team before they merge into the main branch. This ensures high quality code and increases the knowledge of the whole team. Within this feature is the ability to post comments, browse file changes, check commits, or vote on code approval decisions.
- Free of charge – we must not forget that Git is available for free to anyone who needs it. So you don’t have any extra expenses when working with it.
Git and Java programming
There are a large number of programming languages nowadays. If you choose to program in Java but want to use Git, version Eclipse JGit is a good choice. This is a licensed and lighter Java that implements the Git version control system. Using this version of Java is simple and fast, so it doesn’t complicate your work unnecessarily.
There are several ways to link your project to JGit and start writing code. The simplest one is to use the Maven tool. Integration is achieved by adding <dependencies> to the file pom.xml. The result should look like this:
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>4.6.0.201612231935-r</version>
</dependency>
You can find the latest version of JGit in the Maven Central repository. After adding <dependencies> to the file pom.xml Maven should automatically get and use everything you’ll need from the JGit library to get the job done.
You must then create a repository, which you do using the init command:
Git git = Git.init().setDirectory(“/path/to/repo”).call();
To copy a repository, use the cloneRepository command:
Git git = Git.cloneRepository()
.setURI(“https://github.com/eclipse/jgit.git”)
.setDirectory(“/path/to/repo”)
.call();
You can also use different objects in JGit, such as blob, commit or tag. Each one has their own command for it.
Git a GitHub
Along with Git, you may also see GitHub. However, these two terms mean two different things, so it’s important not to confuse them. GitHub is a web hosting provider for software development and version control using Git.
GitHub offers distributed source code management through Git. In addition, it also provides users with other features. These include, for example:
- regulates access,
- monitors reported errors,
- monitors requirements for new features,
- manages the tasks,
- supports continuous integration.
GitHub desktop also provides free hosting for open-source projects and, as of 2019, allows you to host private repositories for free.
The development of GitHub started in 2008, when it was launched. Its developers and founders were Tom Preston-Werner, Chris Wanstrath, PJ Hyett and Scott Chacon. Ten years after its launch, GitHub became a subsidiary of Microsoft.
Git vs. GitHub vs. GitLab
Another system that uses Git is GitLab. It is a web-based Git repository with wikis, or sites that allow users to add content, and with support for bug tracking. Like GitHub, GitLab provides hosting, but also allows the software to be used on third-party servers.
GitLab was written by Dmitriy Zaporozhets and Sytse “Sid” Sijbrandij in Ruby. Shortly after its launch, GitLab split into two different tools:
- GitLab CE: Community Edition
- GitLab EE: Enterprise Edition
The individual tools differ from each other in some functions.
Another interesting thing is that GitLab is very popular. It is used by well-known companies such as SpaceX, IBM and Alibaba Group.
Use Git yourself
Using Git is quick and easy. It will bring a lot of benefits not only to you, but also to your whole team. Working together will be much more flexible and productive thanks to this system. In addition, knowledge of Git can open up new opportunities for you. Take a look at the job offers we currently have available and try your hand at working as a senior Java developer or junior Java developer.