Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Gitlab Cookbook
Gitlab Cookbook

Gitlab Cookbook: Over 60 hands-on recipes to efficiently self-host your own Git repository using GitLab

Arrow left icon
Profile Icon van Baarsen
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3 (3 Ratings)
Paperback Dec 2014 172 pages 1st Edition
eBook
$19.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon van Baarsen
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3 (3 Ratings)
Paperback Dec 2014 172 pages 1st Edition
eBook
$19.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$19.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Gitlab Cookbook

Chapter 2. Explaining Git

In this chapter, we will cover the following recipes:

  • Generating your SSH key on Unix-like systems
  • Generating your SSH key on Windows
  • Adding your SSH key to GitLab
  • Creating your first Git project
  • Cloning your repository and pushing code to it
  • Working with branches
  • Performing a rebase
  • Squashing your commits

Introduction

Before you can use GitLab, you need to know a little about Git itself, what Git is, and what pushing code is. As Git is a very complex system and is worthy of a book of its own, I'm just going to cover the basics. You'll learn how to get your SSH key and how to push your first code to GitLab.

Git is in the heart of GitLab. Without it, there would be no GitLab. It is a super powerful source control system, and has some amazing features. We will take a look at some of those feature in this chapter.

In this chapter, I'll assume that you will be using Git over SSH. However, most recipes will work even if you use Git over HTTP.

If you want to learn more about Git, I recommend that you follow the try.github.io course. It's a free online workshop, and you will learn everything related to Git in an interactive way.

Generating your SSH key on Unix-like systems

Generating an SSH key on Linux and OS X is easy; they come with a built-in tool to do this, called ssh-keygen.

How to do it…

In the following steps, we will create an SSH key for your Unix system:

  1. First, we are going to check whether you have any SSH keys present. Open your terminal and enter the following command:
    $ ls ~/.ssh
    
  2. If you have a file named id_rsa.pub or id_dsa.pub, you can skip this recipe.
  3. To generate a new SSH key, you need to open your terminal and enter the following command:
    $ ssh-keygen -t rsa -C "Comment for key"
    

    The comment can be anything you want; it makes it easier for you to see which key it is when you open the key file.

  4. Now, we get to the question of what you want to name your key. Just press Enter.
  5. You will be asked to enter a passphrase. Enter it, and be sure to choose a strong password.

    You should see the following screenshot:

    How to do it…

Your SSH key is now generated.

How it works…

We just created our personal SSH...

Generating your SSH key on Windows

As Windows does not have a fully functioning terminal, we have to take some other steps to install Git and generate our SSH key. We will take a look at how this is done in this recipe.

How to do it…

  1. Go to http://git-scm.com/downloads and click on Windows.
    How to do it…
  2. The download will start automatically. When it's done, you see the following installation window:
    How to do it…
  3. Click on Next and accept the license agreement.
  4. Choose where you want to install Git and click on Next.
  5. You will want the following components to be selected:
    • Windows Explorer integration
    • Associate .git* configuration files with the default text editor
    • Associate .sh files to be run with Bash

    After selecting the preceding components, click on Next. The following screenshot shows you these options:

    How to do it…
  6. Choose where you want to place Git in your start menu and click on Next.
  7. Choose Use Git from Git Bash only and click on Next.
    How to do it…
  8. Select Checkout Windows-style, commit Unix-style line endings, and click on Next.
    How to do it…
  9. Wait until...

Adding your SSH key to GitLab

In order for GitLab to know who we are and check whether we are authorized to commit certain code, we use our SSH key. The combination of the public key and the private key can tell GitLab that we are authorized, and GitLab will allow the operation to be performed.

How to do it…

To set up your SSH key, perform the following steps:

  1. Open GitLab and go to your account settings.
    How to do it…
  2. Click on SSH.
  3. Click on Add SSH Key.
    How to do it…
  4. To get information about your SSH key, enter the following command in your terminal. If you're using Windows, go to step 7:
    $ cat ~/.ssh/id_rsa.pub
    
  5. You should copy the entire content of the output in step 4, as shown in the following screenshot:
    How to do it…
  6. If you're not using Windows, you can move to step 11.
  7. Open the Windows explorer and move to C:\Users\your_username\.ssh.
  8. Right-click on id_rsa.pub and click on Open.
  9. When asked for the program you want to use, select Notepad.
  10. Select the entire content of the file that contains the SSH key.
    How to do it…
  11. We now paste the...

Creating your first Git project

In this recipe, we will take a look at creating your first Git project on your local machine. If you're a Windows user, please make sure that you use Git Bash. This way, you can use the same commands as the ones Linux and OS X users use.

We're going to create a project called super-git.

How to do it…

To create our first Git project, perform the following steps:

  1. Open your terminal and browse to the folder where you want to create your project.
  2. Create a folder named super-git and create the following directory inside it:
    $ mkdir super-git
    $ cd super-git
    
  3. To make this folder a Git project, we need to tell Git to monitor this folder. We do this by typing the following command:
    $ git init
    

    The following screenshot shows you the output for this command:

    How to do it…
  4. Let's create one file to add to the repository. We name it README.md:
    $ echo "HELLO README" > README.md	
    
  5. Now, we will add this new file to Git. This is also known as staging the files:
    $ git...

Cloning your repository and pushing code to it

In this recipe, we will take a look at cloning your repository from GitLab to your local machine. When you use Git Bash on Windows, the commands will be the same.

Getting ready

You need to create a new repository in your GitLab instance. In this example, we will use the repository named super-git.

How to do it…

In the following steps, we will set up our repository and push code to it:

  1. Go to the newly created repository.
  2. Select the URL in the top-right section.
    How to do it…
  3. Go to the folder where you want to check out the project in the terminal. No need to create a new folder for the project.
  4. Enter the Git clone command, and change the URL to the URL you just copied:
    $ git clone URL
    

    In my case, the URL is as follows:

    $ git clone git@146.185.139.107:jeroen/super-git.git
    

    The following screenshot shows you the output of this command:

    How to do it…
  5. You can now go to the folder and check whether it is a Git folder by running the following command:
    $ git status
    

    The following screenshot...

Introduction


Before you can use GitLab, you need to know a little about Git itself, what Git is, and what pushing code is. As Git is a very complex system and is worthy of a book of its own, I'm just going to cover the basics. You'll learn how to get your SSH key and how to push your first code to GitLab.

Git is in the heart of GitLab. Without it, there would be no GitLab. It is a super powerful source control system, and has some amazing features. We will take a look at some of those feature in this chapter.

In this chapter, I'll assume that you will be using Git over SSH. However, most recipes will work even if you use Git over HTTP.

If you want to learn more about Git, I recommend that you follow the try.github.io course. It's a free online workshop, and you will learn everything related to Git in an interactive way.

Generating your SSH key on Unix-like systems


Generating an SSH key on Linux and OS X is easy; they come with a built-in tool to do this, called ssh-keygen.

How to do it…

In the following steps, we will create an SSH key for your Unix system:

  1. First, we are going to check whether you have any SSH keys present. Open your terminal and enter the following command:

    $ ls ~/.ssh
    
  2. If you have a file named id_rsa.pub or id_dsa.pub, you can skip this recipe.

  3. To generate a new SSH key, you need to open your terminal and enter the following command:

    $ ssh-keygen -t rsa -C "Comment for key"
    

    The comment can be anything you want; it makes it easier for you to see which key it is when you open the key file.

  4. Now, we get to the question of what you want to name your key. Just press Enter.

  5. You will be asked to enter a passphrase. Enter it, and be sure to choose a strong password.

    You should see the following screenshot:

Your SSH key is now generated.

How it works…

We just created our personal SSH key: one key is the id_rsa...

Generating your SSH key on Windows


As Windows does not have a fully functioning terminal, we have to take some other steps to install Git and generate our SSH key. We will take a look at how this is done in this recipe.

How to do it…

  1. Go to http://git-scm.com/downloads and click on Windows.

  2. The download will start automatically. When it's done, you see the following installation window:

  3. Click on Next and accept the license agreement.

  4. Choose where you want to install Git and click on Next.

  5. You will want the following components to be selected:

    • Windows Explorer integration

    • Associate .git* configuration files with the default text editor

    • Associate .sh files to be run with Bash

    After selecting the preceding components, click on Next. The following screenshot shows you these options:

  6. Choose where you want to place Git in your start menu and click on Next.

  7. Choose Use Git from Git Bash only and click on Next.

  8. Select Checkout Windows-style, commit Unix-style line endings, and click on Next.

  9. Wait until the...

Left arrow icon Right arrow icon

Description

This book is aimed at developers and devops that have a GitLab server running, and want to be sure they use it to its full potential. This book will also be useful for people looking for a great Git platform, and learn how to set it up successfully. Some system administrating experience on a UNIX-based system would be useful, but is not required.

What you will learn

  • Install and maintain your GitLab instance
  • Work with multiple users, create groups, and configure your project visibility
  • Secure your code with the correct GitLab configuration
  • Make the most of the builtin issue tracker, including merge requests
  • Manage your projects through the GitLab API
  • Set up webhooks and system hooks to receive notifications
  • Manage your GitLab server using LDAP

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 24, 2014
Length: 172 pages
Edition : 1st
Language : English
ISBN-13 : 9781783986842

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Dec 24, 2014
Length: 172 pages
Edition : 1st
Language : English
ISBN-13 : 9781783986842

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 89.97
Gitlab Cookbook
$32.99
Git Best Practices Guide
$29.99
Git Essentials
$26.99
Total $ 89.97 Stars icon

Table of Contents

10 Chapters
1. Introduction and Installation Chevron down icon Chevron up icon
2. Explaining Git Chevron down icon Chevron up icon
3. Managing Users, Groups, and Permissions Chevron down icon Chevron up icon
4. Issue Tracker and Wiki Chevron down icon Chevron up icon
5. Maintaining Your GitLab Instance Chevron down icon Chevron up icon
6. Webhooks, External Services, and the API Chevron down icon Chevron up icon
7. Using LDAP and OmniAuth Providers Chevron down icon Chevron up icon
8. GitLab CI Chevron down icon Chevron up icon
A. Tips and Tricks Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3
(3 Ratings)
5 star 33.3%
4 star 33.3%
3 star 0%
2 star 0%
1 star 33.3%
dblessing Feb 24, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book covers all the details needed to get up and running with git and GitLab. Jeroen does a great job with tough topics for beginners in his introduction to git, installation of GitLab from source and the new Omnibus packages, basic troubleshooting and managing upgrades. This book also provides in-depth coverage of all the GitLab features, GitLab Continuous Integration server (GitLab CI), the GitLab API, and more. I was pleasantly surprised to see the section dedicated to LDAP integration, too. Overall, this book provides a good foundation for GitLab users.
Amazon Verified review Amazon
Erich S. Mar 08, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Dieses Buch liefert in kurzen und verständlichen Beispielen die Grundzüge von GitLab. Da ich selbst von der Gerrit-Welt komme ist GitLab für mich ein weiter Sprung Richtung Development Zukunft.Schmerzlich vermisse ich jedoch Beispiele für die Anbindung an externe Systeme wie JIRA & Jenkins, welche jedoch State of the Art für Developers & DevOps sind.
Amazon Verified review Amazon
John Pitton Sep 05, 2016
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
A lot of the material is outdated. Almost all of what this book covers is listed for free at gitlabdotcomslashhelp. It would be awesome if the book was periodically updated biannually.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.