Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Git for Programmers
Git for Programmers

Git for Programmers: Master Git for effective implementation of version control for your programming projects

By Jesse Liberty
$43.99
Book Jun 2021 264 pages 1st Edition
eBook
$43.99
Print
$54.99
Subscription
$15.99 Monthly
eBook
$43.99
Print
$54.99
Subscription
$15.99 Monthly

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
Buy Now
Table of content icon View table of contents Preview book icon Preview Book

Git for Programmers

Introduction

In this chapter, we will cover the following topics:

  • A very brief history of version control and Git
  • Getting and setting up Visual Studio 2019, GitHub Desktop, and your terminal
  • Getting and installing Git
  • Configuring Git for Visual Studio, GitHub Desktop, and GitHub at the command line

Let's get started!

About this book

"Begin at the beginning," the King said gravely, "and go on till you come to the end, then stop." – Alice in Wonderland

In this book, we will cover Git from the very beginning all the way through to advanced topics. No experience with Git is expected. Though if you have been using Git, you'll probably want to skim the initial chapters. Git is arguably the most popular version control system in the world, but this raises the question: "What is version control?"

Version control

Before version control, I would code a bit and then when I became afraid of losing that code, I would make a backup of my directory. This is slow, inefficient, takes up a lot of disk space, and is very hard to share with others.

A Version Control System (VCS) does all this work for you (and more) and does so in a way that is fast, efficient, and takes up a minimum of disk space. One of the fastest and most efficient is Git, although there are others. This book will not spend a lot of time convincing you that Git is better than the others. First, the market has spoken, and Git prevails. Second, if you've purchased this book, you've already decided. And if you haven't already purchased this book, go do so. I'll wait here.

About the code examples

In order to demonstrate the use of Git, we need to have a small program that we can evolve. The code examples are given in C#, but they are so simple that you'll be able to follow them regardless of your experience with the language. For example, if you can figure out what this does, you're all set.

public class Program
{
    public void PrintHello()
    {
        Console.WriteLine("Hello World!");
    }
}

This code declares a class (don't worry about what that is) named Program. Inside that class is a method (function) called PrintHello that prints Hello World to the console (your screen).

This is about as complex as it gets, and I'll explain each code snippet as we go.

Just a brief history

In July of 2005, after just a few month's work, Linus Torvalds, the genius behind Linux, released Git to meet his own needs, the needs of the Linux community, and eventually, the rest of us. The goal of Git was to be fast and efficient. It succeeded.

While most VCSes at the time were centralized (all the files were kept on a big server), Git uses a distributed system, in which everyone has their own repository. Technically, no central server is required for Git, although if you are working in a team, a central place for sharing code is convenient. But the huge difference is that with Git, the vast majority of your interactions with the VCS are local – right there on your disk.

Tools for working with Git

There are a number of easily confused terms (such as Git versus GitHub) and there are many tools for working with Git – from the command line to Graphical User Interface (GUI) tools. This section will review some of these options.

GitHub, et al.

There are many services that allow you to create shared "repositories" (the location of all the versions of your program). The most famous and popular are GitHub and Microsoft's Azure, as well as BitBucket and GitLab. Azure is a very powerful system for DevOps, while GitHub is a very straightforward way to host your program. We'll be using GitHub in this book. (Recently, Microsoft acquired GitHub for $7.5 billion in stock – and made a huge commitment to GitHub, open source and, of course, to Git.)

Key point: Git is the system we're covering in this book. GitHub is a central repository system for sharing code (we'll make this more specific later in the...

Getting Git

The very first thing you need to do is to install Git on your computer. The official Git site states that "even if Git is already installed on your computer, it is probably a good idea to reinstall to update to the latest version."

Getting Git on Windows

There are also a few ways in which to install Git on Windows. I recommend using the official build. The most recent one is available from the Git website: https://git-scm.com/download/win.

Another way to get Git, and to kill two birds with one stone, is to download and install GitHub Desktop. The installer will also install a command-line version of Git. You can get it at https://desktop.github.com/:

Figure 1.6: Obtaining GitHub Desktop

This book will show its demonstrations on Windows 10, using Git version 2.30.0.windows.2, but the examples should work with just about any version of Git.

Getting Git on a Mac

There are several ways to install Git on a Mac. The easiest is probably...

Configuring Git – the command line

We'll look at configuring Git to personalize throughout this book, but for now, let's add your name and email address so that every entry into Git is stamped appropriately. Enter the command-line command:

git config --global --edit

This will bring up your editor. Find or create the [user] section and add the following:

[user]
name = Jesse Liberty
email = jesseliberty@gmail.com

You will probably want to use your own name and email address.

There are other entries in the config file. Ignore them for now and save and close the file.

Configuring Git – Visual Studio

In Visual Studio for Windows, click on the Git menu and a dialog box will open. On the first tab, enter your username and email address:

Figure 1.8: Setting Git options in Visual Studio

Configuring Git – GitHub Desktop

To configure GitHub Desktop, you'll need an account on GitHub. We'll cover that in the next chapter. Once you do have an account, go to File | Options, select the Accounts tab, and then click on Sign in:

Figure 1.9: Setting up GitHub Desktop

Summary

In this chapter you saw an introduction to the book, listing what is in each chapter. You also saw a quick history of version control and of Git itself.

Next, we took a look at downloading the environments you'll need to follow along: Visual Studio 2019, GitHub Desktop, and PowerShell as your command line. All of these can be obtained for free.

Once the software was downloaded, we looked at how to set up Git, and how to set up the tools we'll be using.

Left arrow icon Right arrow icon

Key benefits

  • Master Git and maintain your projects better through version control
  • Get to grips with Git’s typical workflows, advanced functions, and their implementations
  • Learn the key Git commands to better manage your repository

Description

Whether you’re looking for a book to deepen your understanding of Git or a refresher, this book is the ultimate guide to Git. Git for Programmers comprehensively equips you with actionable insights on advanced Git concepts in an engaging and straightforward way. As you progress through the chapters, you’ll gain expertise (and confidence) on Git with lots of practical use cases. After a quick refresher on git history and installation, you’ll dive straight into the creation and cloning of your repository. You’ll explore Git places, branching, and GUIs to get familiar with the fundamentals. Then you’ll learn how to handle merge conflicts, rebase, amend, interactive rebase, and use the log, as well as explore important Git commands for managing your repository. The troubleshooting part of this Git book will include detailed instructions on how to bisect, blame, and several other problem handling techniques that will complete your newly acquired Git arsenal. By the end of this book, you’ll be using Git with confidence. Saving, sharing, managing files as well as undoing mistakes and basically rewriting history will be a breeze.

What you will learn

Create remote and local repositories and learn how to clone them Understand the difference between local and remote repositories Use, manage, and merge branches back into the main branch Utilize tools to manage merge conflicts Manage commits on your local machine through interactive rebasing Use the log to gain control over all the data in your repository Use bisect, blame, and other tools to undo Git mistakes

Product Details

Country selected

Publication date : Jun 30, 2021
Length 264 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781801075732
Category :
Concepts :

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
Buy Now

Product Details


Publication date : Jun 30, 2021
Length 264 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781801075732
Category :
Concepts :

Table of Contents

16 Chapters
Preface Chevron down icon Chevron up icon
1. Introduction Chevron down icon Chevron up icon
2. Creating Your Repository Chevron down icon Chevron up icon
3. Branching, Places, and GUIs Chevron down icon Chevron up icon
4. Merging, Pull Requests, and Handling Merge Conflicts Chevron down icon Chevron up icon
5. Rebasing, Amend, and Cherry-Picking Chevron down icon Chevron up icon
6. Interactive Rebasing Chevron down icon Chevron up icon
7. Workflow, Notes, and Tags Chevron down icon Chevron up icon
8. Aliases Chevron down icon Chevron up icon
9. Using the Log Chevron down icon Chevron up icon
10. Important Git Commands and Metadata Chevron down icon Chevron up icon
11. Finding a Broken Commit: Bisect and Blame Chevron down icon Chevron up icon
12. Fixing Mistakes Chevron down icon Chevron up icon
13. Next Steps Chevron down icon Chevron up icon
14. Other Books You May Enjoy Chevron down icon Chevron up icon
15. Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Top Reviews
No reviews found
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.