Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Git Essentials ??? Second Edition
Git Essentials ??? Second Edition

Git Essentials ??? Second Edition: Create, merge, and distribute code with Git, the most powerful and flexible versioning system available , Second Edition

Arrow left icon
Profile Icon Santacroce
Arrow right icon
NZ$14.99 NZ$45.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (3 Ratings)
eBook Nov 2017 238 pages 2nd Edition
eBook
NZ$14.99 NZ$45.99
Paperback
NZ$56.99
Subscription
Free Trial
Arrow left icon
Profile Icon Santacroce
Arrow right icon
NZ$14.99 NZ$45.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (3 Ratings)
eBook Nov 2017 238 pages 2nd Edition
eBook
NZ$14.99 NZ$45.99
Paperback
NZ$56.99
Subscription
Free Trial
eBook
NZ$14.99 NZ$45.99
Paperback
NZ$56.99
Subscription
Free Trial

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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Git Essentials ??? Second Edition

Git Fundamentals - Working Locally

In this chapter, we will dive deep into some of the fundamentals of Git; it is essential to understand well how Git thinks about files, its way of tracking the history of commits, and all the basic commands that we need to master, in order to become proficient.

Digging into Git internals

In this second edition of Git Essentials, I slightly changed my approach in explaining how Git works; instead of explaining with words and figures, this time I want to show you how Git works internally with only the help of the shell, allowing you to follow all the steps on your computer and hoping that these will be clear enough for you to understand.

Once you know the fundamentals of the Git working system, I think the rest of the commands and patterns will be clearer, allowing you to accomplish proficiently your daily work, getting out of trouble when needed.

So, it's time to start digging inside the true nature of Git; in this chapter, we will get in touch with the essence of this powerful tool.

Git objects

In Chapter 1, Getting Started with Git, we created an empty folder (in C:\Repos\MyFirstRepo) and then we initialized a new Git repository, using the git init command.

Let's create a new repository to refresh our memory and then start learning a little bit more about Git.

In this example, we use Git to track our shopping list before going to the grocery; so, create a new grocery folder, and then initialize a new Git repository:

[1] ~
$ mkdir grocery

[2] ~
$ cd grocery/

[3] ~/grocery
$ git init
Initialized empty Git repository in C:/Users/san/Google Drive/Packt/PortableGit/home/grocery/.git/

As we have already seen before, the result of the git init command is the creation of a .git folder, where Git stores all the files it needs to manage our repository:

[4] ~/grocery (master)
$ ll
total 8
drwxr-xr-x 1 san 1049089 0 Aug 17 11:11 ./
drwxr-xr-x 1 san 1049089 0...

Even deeper - the Git storage object model

Okay, now we know there are different Git objects, and we can inspect inside them using some plumbing commands. But how and where does Git store them?

Do you remember the .git folder? Let's put our nose inside it:

[20] ~/grocery (master)
$ ll .git/
total 13
drwxr-xr-x 1 san 1049089   0 Aug 18 17:22 ./
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 ../
-rw-r--r-- 1 san 1049089 294 Aug 17 13:52 COMMIT_EDITMSG
-rw-r--r-- 1 san 1049089 208 Aug 17 13:51 config
-rw-r--r-- 1 san 1049089  73 Aug 17 11:11 description
-rw-r--r-- 1 san 1049089  23 Aug 17 11:11 HEAD
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 hooks/
-rw-r--r-- 1 san 1049089 217 Aug 18 17:22 index
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 info/
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 logs/
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15 objects/
drwxr-xr-x 1 san 1049089   0 Aug 18 17:15...

Git doesn't use deltas

Now it's time to investigate another well-known difference between Git and other versioning systems. Take Subversion as an example: when you do a new commit, Subversion creates a new numbered revision that only contains deltas between the previous one; this is a smart way to archive changes to files, especially among big text files, because if only a line of text changes, the size of the new commit will be much smaller.

Instead, in Git even if you change only a char in a big text file, it always stores a new version of the file: Git doesn't do deltas (at least not in this case), and every commit is actually a snapshot of the entire repository.

At this point, people usually exclaim: "Gosh, Git waste a large amount of disk space in vain!". Well, this is simply untrue.

In a common source code repository, with a certain amount of commit...

Wrapping up

It's time to summarize all the concepts illustrated since now.

An image, as they say, is worth a thousand words, so here you can find a picture representing the actual state of our repository, thanks to the git-draw tool (https://github.com/sensorflo/git-draw):

In this graphic representation, you will find a detailed diagram that represents the current structure of the newly created repository; you can see trees (yellow), blobs (white), commits (green), and all relationships between them, represented by oriented arrows.

Note how the direction of the arrow joining the commit comes from the second commit and goes to the first, or from descendant to its ancestor; it may seem a detail, but it is important that graphic representations such as these are properly indicated in order to correctly highlight the relationship that binds the commits between them (it is always...

Git references

In the previous section, we have seen that a Git repository can be imagined as a tree that, starting from a root (the root-commit), grows upward through one or more branches.

These branches are generally distinguished by a name. In this Git is no exception; if you remember, the experiments conducted so far led us to commit to the master branch of our test repository. Master is precisely the name of the default branch of a Git repository, somewhat like trunk is for Subversion.

But Subversion analogies end here: we will now see how Git handles branches, and for Subversion users it will be a little surprising.

It's all about labels

In Git, a branch is nothing more than a label, a mobile label placed...

Staging area, working tree, and HEAD commit

Until now, we have barely named the staging area (also known as an index), while preparing files to make a new commit with the git add command.

Well, the staging area purpose is actually this. When you change the content of a file, when you add a new one or delete an existing one, you have to tell Git what of these modifications will be part of the next commit: the staging area is the container for this kind of data.

Let's focus on this right now; move to the master branch, if not already there, then type the git status command; it allows us to see the actual status of the staging area:

[1] ~/grocery (master)
$ git status
On branch master
nothing to commit, working tree clean

Git says there's nothing to commit, our working tree is clean. But what's a working tree? Is it the same as the working directory we talked about...

Rebasing

Now I want to tell you something about the git rebase command; a rebase is a common term while using a versioning system, and even in Git this is a hot topic.

Basically, with git rebase you rewrite history; with this statement, I mean you can use rebase command to achieve the following:

  • Combine two or more commits into a new one
  • Discard a previous commit you did
  • Change the starting point of a branch, split it, and much more

Reassembling commits

One of the widest uses of the git rebase command is for reordering or combining commits. For this first approach, imagine you have to combine two different commits.

Suppose we erroneously added half a grape in the shoppingList.txt file, then the other half, but at the end...

Merging branches

Yes, I know, probably there's a thought on your mind since we start playing with branches: why he doesn't talk about merging?.

Now the moment has arrived.

In Git, merging two (or more!) branches is the act of making their personal history meet each other. When they meet, two things can happen:

  • Files in their tip commit are different, so some conflict will rise
  • Files do not conflict
  • Commits of the target branch are directly behind commits of the branch we are merging, so a fast-forward will happen

In the first two cases, Git will guide us assembling a new commit, a so-called merge commit; in the fast-forward case instead, no new commit is needed: Git will simply move the target branch label to the tip commit of the branch we are merging.

Let's give it a try.

We can try to merge the melons branch into the master one; to do so, you have to check...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Master all the basic concepts of Git to protect your code and make it easier to evolve
  • Use Git proficiently, and learn how to resolve day-by-day challenges easily
  • This step-by-step guide is packed with examples to help you learn and work with Git’s internals

Description

Since its inception, Git has attracted skilled developers due to its robust, powerful, and reliable features. Its incredibly fast branching ability transformed a piece of code from a niche tool for Linux Kernel developers into a mainstream distributed versioning system. Like most powerful tools, Git can be hard to approach since it has a lot of commands, subcommands, and options that easily confuse newcomers. The 2nd edition of this very successful book will help you overcome this fear and become adept in all the basic tasks in Git. Building upon the success of the first book, we start with a brief step-by-step installation guide; after this, you'll delve into the essentials of Git. For those of you who have bought the first edition, this time we go into internals in far greater depth, talking less about theory and using much more practical examples. The book serves as a primer for topics to follow, such as branching and merging, creating and managing a GitHub personal repository, and fork and pull requests. You’ll then learn the art of cherry-picking, taking only the commits you want, followed by Git blame. Finally, we'll see how to interoperate with a Subversion server, covering the concepts and commands needed to convert an SVN repository into a Git repository. To conclude, this is a collection of resources, links, and appendices to satisfy even the most curious.

Who is this book for?

If you are a software developer with little or no experience of versioning systems, or you are familiar with other centralized versioning systems, then this book is for you. If you have experience in server and system management and need to broaden your use of Git from a DevOps perspective, this book contains everything you need.

What you will learn

  • Master Git fundamentals
  • Be able to "visualize," even with the help of a valid GUI tool
  • Write principal commands in a shell
  • Figure out the right strategy to run change your daily work with few or no annoyances
  • Explore the tools used to migrate to Git from the Subversion versioning system without losing your development history
  • Plan new projects and repositories with ease, using online services, or local network resources

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Nov 08, 2017
Length: 238 pages
Edition : 2nd
Language : English
ISBN-13 : 9781787283176
Vendor :
GitHub
Category :
Languages :
Tools :

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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Nov 08, 2017
Length: 238 pages
Edition : 2nd
Language : English
ISBN-13 : 9781787283176
Vendor :
GitHub
Category :
Languages :
Tools :

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 NZ$7 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 NZ$7 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total NZ$ 209.97
Git Version Control Cookbook
NZ$71.99
Mastering Git
NZ$80.99
Git Essentials ??? Second Edition
NZ$56.99
Total NZ$ 209.97 Stars icon
Banner background image

Table of Contents

7 Chapters
Getting Started with Git Chevron down icon Chevron up icon
Git Fundamentals - Working Locally Chevron down icon Chevron up icon
Git Fundamentals - Working Remotely Chevron down icon Chevron up icon
Git Fundamentals - Niche Concepts, Configurations, and Commands Chevron down icon Chevron up icon
Obtaining the Most - Good Commits and Workflows Chevron down icon Chevron up icon
Migrating to Git Chevron down icon Chevron up icon
Git Resources Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(3 Ratings)
5 star 0%
4 star 33.3%
3 star 33.3%
2 star 33.3%
1 star 0%
Apu586 Sep 25, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Awesome book. You'll understand why git works the way it works. Takes you through the basic git structure to understand the advanced commands. Also covers the mistakes one may face. Great for beginners and experienced users alike.
Amazon Verified review Amazon
ian rust Feb 04, 2021
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Let me start with the positive. The information is good. If you put in the time to interpret what the author is saying you will learn some finer details of git, and that information is valuable.However... there are some issues:1) the first 40 pages or so were just filler. Big pictures with 2 or 3 sentences stating the obvious. Could have been condensed into... at least half as many pages. So my initial impressions is that the book was a jokeHowever, come chapter 2 it really picked up, and started delivering valuable information.2) there are places where his explanations are just completely lackluster. I have no doubt that I could have worded them much better myself. It took me 4 reads to understand what he was trying to say about reset --soft, for example.3) The author did not organize the material. Reading it was like... sifting through a messy room looking for an item you lost. For example, information on the --help command can be found 30 pages apart, just kind of scattered in places where it doesn't belong. That information should have just been in one place, up front. I wouldn't mention this if I hadn't noticed multiple times where information that should be grouped together is just strewn around in random places4) The author has a bad writing style where he shows you something but doesn't explain it, and tells you he will explain it in a while. You then have to remember that thing and remain confused while listening to him talk - until he finally gets around to explaining himself. Sometimes it takes over 30 pages to reach a conclusion.5) I said the information is good, but it isn't phenomenal. It isn't comprehensive or anything.6) It just reeks of laziness / bad writing ability.HOWEVER.... after you stumble through this, and take notes (I recommend taking notes over trying to sift through the disorganized mess of a book if you forgot something)... you will have the information you need and be proficient. That is why I gave it 3 stars.From what I understand alot of chapter 2's information - the books only redeeming quality, the information provided - was actually added into the 2nd edition after people complained. The fact this needed to be asked for is really a testament to how little effort the author put into this.Would I recommend you buy it? Only if you can't find a better book with glowing reviews. I think you probably can. It does have the information you need, but you will have to put unnecessary effort into sifting through / interpreting it. The author just is not a good writer, I myself could have written a better book.
Amazon Verified review Amazon
Cliente de Amazon Dec 01, 2019
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Otro pésimo libro de Packt, no lo recomiendo en lo absoluto.
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.