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

eBook
$9.99 $29.99
Paperback
$38.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Chile

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

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 : 9781787120723
Vendor :
GitHub
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
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

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Chile

Standard delivery 10 - 13 business days

$19.95

Premium delivery 3 - 6 business days

$40.95
(Includes tracking information)

Product Details

Publication date : Nov 08, 2017
Length: 238 pages
Edition : 2nd
Language : English
ISBN-13 : 9781787120723
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 $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 $ 142.97
Git Version Control Cookbook
$48.99
Mastering Git
$54.99
Git Essentials ??? Second Edition
$38.99
Total $ 142.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

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela