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
$15.99 per month
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 a Packt Subscription?

Free for first 7 days. $15.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

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 a Packt Subscription?

Free for first 7 days. $15.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 : 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

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.