Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Git Essentials
Git Essentials

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

eBook
$9.99 $21.99
Paperback
$26.99
Subscription
Free Trial
Renews at $19.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
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

Chapter 2. Git Fundamentals – Working Locally

In this chapter, we will go deep into some of the fundamentals of Git. It is essential to understand 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.

Repository structure and file status life cycle

The first thing to understand while working with Git is how it manages files and folders within the repository. This is the time to analyze a default repository structure.

The working directory

In Chapter 1, Getting Started with Git, we created an empty folder and initialized a new repository using the git init command (in C:\Repos\MyFirstRepo). Starting from now, we will call this folder the working directory. A folder that contains an initialized Git repository is a working directory. You can move the working directory around your file system without losing or corrupting your repository.

Within the working directory, you also learned that there is a .git directory. Let's call it the git directory from now on. In the git directory there are files and folders that compose our repository. Thanks to this, we can track the file status, configure the repository, and so on.

File statuses

In Chapter 1, Getting Started with Git, we used two different...

Working with repositories

Let's get our hands dirty!

If you are reading this book, you are probably a programmer, as I am. Using a programming language and its source and binary files to exercise could be fine. However, I don't want to distract you from understanding a language you probably don't use every day. So, let's settle things once and for all. When needed, I will use a nice markup language called Markdown (see http://daringfireball.net/projects/markdown/).

Apart from being simple yet powerful, Markdown silently became the favorite choice while typing readme files (for example, GitHub uses it extensively) or comments in forums or other online discussion places, such as StackOverflow. Mastering it is not our goal, but to be able to do the basic things is surely a skill that can be useful in the future.

Before you proceed, create a new folder for exercises, for example, C:\Repos\Exercises. We will use different folders for different exercises.

Unstaging a file

Consider...

Viewing the history

Let's continue where we left off in Chapter 1, Getting Started with Git. Walk into C:\Repos\MyFirstRepo and start a new Bash shell using the right-click shortcut. Now, use the git log command to see the history of our repository, as shown in this screenshot:

Viewing the history

The git log command is very useful and powerful. With this command, we can get all the commits that we did one by one, each one with its most important details. It's now time to become more familiar with them.

Anatomy of a commit

Commits are the building blocks of a repository. Every repository is nothing more than an ordered sequence of commits. If you have a math background, you have probably already identified an acyclic direct graph in it.

The commit snapshot

Every time we commit something, Git wraps all the files included in a binary blob file. This is one of the most important characteristics of Git. While other versioning systems save files one by one (perhaps using deltas), Git produces a snapshot every...

Taking another way – Git branching

Now, it's time to introduce one of the most used features of a versioning system: branching. This is a thing that you will use extensively and a thing that Git does well.

Anatomy of branches

A branch is essentially another way your repository takes. While programming, you will use branches to experiment with changes, without breaking the working code. You will use them to keep track of some extensive work, such as the development of a new feature, to maintain different versions or releases of your project. To put it simply, you will use it always.

When in a Git repository, you are always in a branch. If you pay attention to the Bash shell, you can easily find the branch that you are on at the moment. It is always at the prompt, within brackets, as shown here:

Anatomy of branches

The master branch is, conventionally, the default branch. When you do your first commit in a brand new repo, you actually do the first commit in the master branch.

During the course of the...

Stashing

Working of different features in parallel does not make a developer happy, but sometimes it happens. So, at a certain point, we have to break the work on a branch and switch to another one. However, sometimes, we have some modifications that are not ready to be committed, because they are partial, inconsistent, or even won't compile. In this situation, Git prevents you from switching to another branch. You can only switch from one branch to another if you are in a clean state:

Stashing

To quickly resolve this situation, we can stash the modifications, putting them into a sort of box, ready to be unboxed at a later time.

Stashing is as simple as typing the git stash command. A default description will be added to your stash, and then modifications will be reverted to get back in a clean state:

Stashing

To list actual stashes, you can use the list subcommand:

Stashing

Once you have done the other work, you can go back to the previous branch and apply the stash to get back to the previous "work in progress...

Repository structure and file status life cycle


The first thing to understand while working with Git is how it manages files and folders within the repository. This is the time to analyze a default repository structure.

The working directory

In Chapter 1, Getting Started with Git, we created an empty folder and initialized a new repository using the git init command (in C:\Repos\MyFirstRepo). Starting from now, we will call this folder the working directory. A folder that contains an initialized Git repository is a working directory. You can move the working directory around your file system without losing or corrupting your repository.

Within the working directory, you also learned that there is a .git directory. Let's call it the git directory from now on. In the git directory there are files and folders that compose our repository. Thanks to this, we can track the file status, configure the repository, and so on.

File statuses

In Chapter 1, Getting Started with Git, we used two different...

Left arrow icon Right arrow icon

Description

If you are a software developer with little or no experience of versioning systems, or are familiar with other centralized versioning systems, then this book is for you. If you have some experience working with command lines or using Linux admin or just using Unix and want to know more about Git, then this book is ideal for you.

Who is this book for?

If you are a software developer with little or no experience of versioning systems, or are familiar with other centralized versioning systems, then this book is for you. If you have some experience working with command lines or using Linux admin or just using Unix and want to know more about Git, then this book is ideal for you.

What you will learn

  • Create, branch, and merge a local repository
  • Transport your work to a remote repository working in a centralized manner
  • Organize your source code using feature branches
  • Organize the development flow
  • Get a meaningful changelog using clear commit messages
  • Collaborate with teammates without any impediments
  • Experiment with your code without affecting functional code files
  • Explore some tools used to migrate to Git from other versioning systems without losing your development history
  • Extend your knowledge of Git with some useful resources

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 28, 2015
Length: 168 pages
Edition : 1st
Language : English
ISBN-13 : 9781785287275
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 : Apr 28, 2015
Length: 168 pages
Edition : 1st
Language : English
ISBN-13 : 9781785287275
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 $ 105.97
Git Essentials
$26.99
Git Best Practices Guide
$29.99
Git Version Control Cookbook
$48.99
Total $ 105.97 Stars icon
Banner background image

Table of Contents

8 Chapters
1. Getting Started with Git Chevron down icon Chevron up icon
2. Git Fundamentals – Working Locally Chevron down icon Chevron up icon
3. Git Fundamentals – Working Remotely Chevron down icon Chevron up icon
4. Git Fundamentals – Niche Concepts, Configurations, and Commands Chevron down icon Chevron up icon
5. Obtaining the Most – Good Commits and Workflows Chevron down icon Chevron up icon
6. Migrating to Git Chevron down icon Chevron up icon
7. Git Resources Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9
(9 Ratings)
5 star 55.6%
4 star 0%
3 star 33.3%
2 star 0%
1 star 11.1%
Filter icon Filter
Top Reviews

Filter reviews by




Krunal Jhaveri Jul 10, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I bought the kindle copy for it, and it was a great ready to get all my basics right for git. Its really helpful to ace yourself in this technology world with one of the most powerful version control systems. I suggested one reading it once every week and keep it handy to get your git essentials in place
Amazon Verified review Amazon
Paul W Oct 06, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good solid explanations of both the overall concepts and tricky details. Separate chapter for those migrating from Subversion.
Amazon Verified review Amazon
D. Bowser Jun 10, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is an awesome text for learning and reviewing GIT functions. I work with new developers/designers regularly and explaining GIT can be rough if they've never used a VCS (version control system) before. Mr. Santacroce does an excellent job of breaking down the essentials so that you feel like a GIT ninja! I would recommend this book for both beginners and experienced users as there are always new things to learn and the diagrams make complicated code machinations seem like routine procedures. GIT is a valuable dev tool, but most users only scratch the surface of its capabilities. With this text you can take your GIT game to the next level!
Amazon Verified review Amazon
zl Jan 18, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
good book. Real life examples.
Amazon Verified review Amazon
R. Alexander Sep 05, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I had been interested in learning about Git and GitHub for a long time, but always had trouble getting started. Based on previous reviews of Git Essentials, I decided to give it a try. I dove straight in and worked through the whole book relatively quickly. I now feel that I have a solid understanding of Git functionality and best practices. Ferdinando Santacroce doesn't bore you with a million little details or too much theory, and at the same time, he doesn't make you feel like you're missing part of the story by leaving too much out. Further, Git Essentials has a nice balance of seriousness and humor. It stays on point without being dry.If you know what Git is and would like to incorporate it into your workflow, I'd highly recommend this book as a means for getting started.
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.