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

eBook
€13.98 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
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 : 9781783986859

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 68.97
Gitlab Cookbook
€24.99
Git Best Practices Guide
€22.99
Git Essentials
€20.99
Total 68.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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.