An introduction to Git (part 1)

By shane
Tue, 2015-01-20 09:18
5 comments

Share with Others

If you are not already using Git on your Drupal websites or projects, now is the time to learn. Over the next week or two, I will be going over a brief introduction to Git in 5 parts. In the following post, I will provide a quick overview of Git and Git hosting services. In subsequent parts, I will walk through examples of Git commands and what they do. In the 5th and final part I will bring it all together with examples of how Git is commonly used with Drupal.

Git is one of the secrets from my 5 secrets to becoming a Drupal 7 Ninja ebook, and much of the following posts are from this ebook. To learn more about Git and the other secrets, please consider purchasing the ebook or signing up for the 5 secrets email newsletter which will give you more information about the 5 secrets.

VERSION CONTROL (WITH GIT)... NEVER LOSE YOUR CODE OR YOUR MIND AGAIN

You have probably heard of Version Control or Git before. If you are not already using a Version Control system now is the time to start. According to the Git website:

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and
efficiency.

So what exactly is a Version Control System? To keep things simple, it is basically a way to track changes that you have made to files over a period of time. It gives you the ability to not only track those changes, but roll back to a previous point in time if something goes bad. A version control system also makes it much easier for multiple developers to work on a single project without stepping on each other’s toes.

Git is a Distributed Version Control System, which means that every developer working on a project has a full copy of the repository. A repository is just another name for how the project and its files are stored in the version control system. Generally when working with Git you will have some type of server that you push your changes too. Often this will be a third party service like GitHub, Bitbucket, or one of the many other alternatives.

Choosing the Right Service to Host Your Git Repository

There are a lot of options to consider when choosing where (and if) you want to use a third party service to host the Git repository for your project. These services provide a lot of useful tools that make working with your Git repository easier. Some standard tools to keep an eye out for include:

  • Ability to view the code of your Git repository
  • Issue or Bug tracking
  • Create and manage Git branches of code
  • Built in Code Review Tools
  • Collaboration tools to make building a software project with a team easier

There are typically many more features, but that is a basic list that almost all Git hosting services offer. It is best to do your own research here as opinions tend to vary on which is the best. The most popular one is probably Github. It provides a great interface and great collaboration tools. Github is especially popular in the open source software market. Github is free to use as long as you make your Git repository public. Github charges for you to have a private repository. Github bases its fees on the number of private repositories you require.

Bitbucket is another popular choice. Bitbucket has free Git project hosting for teams of 5 or less. Bitbucket allow for an unlimited number of public or private Git repositories. All of the fees for Bitbucket are based on the number of people on the team (not the number of repositories). This distinct difference between Bitbucket and Github often helps you decide based on the type of project you are building and the team size (assuming you are basing your decision only on price). There are many other options out there, but these are the most widely used that I am aware of.

So which Git project hosting service do I use? Well... both actually. I prefer using Github for any type of open source project. Github’s interface and collaboration tools are slightly better than Bitbucket’s in my opinion. I do however use Bitbucket much more than I use Github. Because I often tend to work on projects in small teams, and I need private repositories for much of my work, Bitbucket is the logical choice. I also don’t want to discount the tools in Bitbucket as they too are really good (Github is just slightly more user friendly).

Ninja Lesson: All Git Hosting services will follow the same constructs. Learn Git and you can easily adapt to the hosting service of your choosing.

Getting Started with Git

So how do you go about getting start with Git if you have never worked with a Version Control System before? The first steps are to start by downloading Git for your operating system. Once you have Git downloaded and installed, you may be tempted to download a Git GUI client. You can browse for one of your choosing and try one out (I have used GitEye with some success in the past as it provides a Linux version). I won’t be covering Git GUI clients because frankly I don’t like using them and I think they shroud what is actually happening (sometimes making it seem more confusing than it has to be). Even if you do want to use a Git GUI client, I highly suggest learning the basics from the command line first. This will give you a much deeper understanding of what various commands are doing and how the entire Git process works.

Intro to Git Part 1 Summary

In the subsequent 4 parts, you will be able to follow along to create your first Git repository, learn the basics of Git commands, create a larger Git repository for your Drupal website, and learn how to pull down external Git repositories (like those on Github or Bitbucket).

So start out by following the instructions for your Operating system and getting Git installed. In the introduction to Git part 2, we will get started with some basic Git commands and configuration.

Comments

How often will you be posting the 5 parts of your Git blog series? I see that the first part was posted 8 days ago. So will that be the time interval for each part in the series? 8-10 days? So it would take almost 2 months to run through the series? Just curious as I didn't really that much time to wait to get up to speed on Git.

The timeline was a little slow getting started, but the final two parts of the Introduction to Git series will be up this week.

Thanks for the comment.

Post new comment