Git, GitHub and GitLab and their benefits

Git and GitHub are services you’re bound to come across when you’re coding. Over the years, Git has become the global standard for version control, used by millions of people. But what does it mean in practice, and how can it benefit 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 the work of multiple developers working on a particular piece of software. Git offers developers speed, ease of use and support for distributed, non-linear workflows.

The fact that Git is a distributed system means that a clone of the project is 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 is available to other team members working on the project. Other developers can also track the full history and other stored versions.

Git can be used by professionals and novices alike
Git can be used by professionals and novices alike.

Git has grown in popularity over the past few years, largely due to the flexibility it offers. It is also popular because it is free and open source software, distributed under the GPL-2.0 licence.

Git history

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 in the same way as BitKeeper. However, none of the free systems available met his needs.

Torvalds had specific requirements that the system had to meet. One of them was that a fix within the system should take no more than three seconds, and that the system should support a workflow similar to BitKeeper’s.

As none of the software Torvalds found met his requirements, he decided to write his own. Development of Git began on 3 April 2005, with initial testing taking place on 29 April 2005.

After testing Git, Torvalds handed over the maintenance of Git to Jun Haman, the project’s main contributor, who was then 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 changes, the system creates a commit. A commit is a snapshot of all your files at one point in time. Each commit creates links to the next commit, creating a clear and handy development history chart.

Thanks to the development history, you can always go back to a previous version to review it and see where a bug occurred, for example.

Git branches

Git works on the basis of branches. Each developer has their own branch, or code repository, outside the main branch. When work on the branch is finished, you can merge it back into the main branch or directly into trunk.

Git files

In addition to branches, it is also important to know about files, which can be in one of three states, namely:

  • modified,
  • staged,
  • committed.

In the case of the first state, the modifications are in the working directory. They are not part of the commit or development history. However, to get them into the history, the developer must stage them.

When the developer is happy with their work and the staging area, they can include everything in the final phase, the commit. The commit then becomes part of the repository’s 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 bits of information as change lists. To them, it is just a set of files and changes at a particular time.

In Git, it’s different. It looks at data as a collection of snapshots that are part of a system or file. Every time you commit and save something to the system, it takes a photograph, or screenshot, of what the files look like at a particular point in time.

Git then saves a reference to the snapshot, and does not save the file again if it is unchanged after further work. It refers to an earlier 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 hard drive, so changes and modifications are instantaneous.

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. There’s no need to download chunks 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?

Currently, most projects have multiple developers working in parallel. 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 a previous version of the code. All this and much more can be provided by the handy Git tool, which is free and fast.

Git has many great benefits
You don’t have to pay anything to download Git.

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 not sure about, don’t be afraid to ask.
  • Simplicity – using Git is not difficult and is often part of programming for beginners. Learning the procedures and how to use the system to your advantage is made easier by the wealth of information available on the internet. As well as expert articles, you can watch free videos or read various books for more information.
  • Concurrent development – Git allows each developer to 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 requests – many developers also appreciate the change request feature, which allows them to discuss code changes with the whole team before they are merged into the main branch. This ensures high quality code and increases the knowledge of the whole team. Within this feature, you can post comments, browse file changes, review commits or vote on code approval decisions.
  • Free of charge – remember that Git is free for anyone who needs it. So there’s no extra cost to using it.

Git and Java programming

There are many programming languages available today. If you are coding in Java but want to use Git, the Eclipse JGit version is a good choice. This is a licensed and lightweight Java that implements the Git version control system. Using this version of Java is simple and fast, so it won’t make your work any harder.

There are several ways to connect your project to JGit and start writing code. The easiest is to use the Maven tool. Integration is achieved by adding <dependencies> to the pom.xml file. 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>

The latest version of JGit can be found in the Maven Central repository. After adding <dependencies> to the pom.xml file, Maven should automatically fetch and use everything you’ll need from the JGit library to get the job done.

Git also enables Java programming
The JGit version is free.

You then need to 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 has its own command.

Git vs 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, Git Hub provides users with other features. It:

  • controls access,
  • tracks reported bugs,
  • tracks requests for new features,
  • manages tasks,
  • supports continuous integration.

The GitHub desktop also provides free hosting for open-source projects and, as of 2019, allows you to host private repositories for free.

Development of GitHub began 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 in Ruby by Dmitriy Zaporozhets and Sytse “Sid” Sijbrandij. Shortly after its launch, GitLab split into two different tools:

  • GitLab CE: Community Edition
  • GitLab EE: Enterprise Edition

The tools differ in some features.

Another interesting thing is that GitLab is very popular. It is used by well-known companies such as SpaceX, IBM and Alibaba Group.

Git is an important part of every development team.
Mastering Git will open up new job opportunities for you.

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. Plus, knowing Git can open up new opportunities for you. Take a look at our current job offers and try your hand at working as a Java developer senior or Java developer junior!

Let us know about you