Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Git Essentials
Git Essentials
Git Essentials
Ebook351 pages2 hours

Git Essentials

Rating: 4.5 out of 5 stars

4.5/5

()

Read preview

About this ebook

About This Book
  • 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 tasks easily
  • A step-by-step guide, packed with examples to help you learn and work with Git internals
Who This Book Is 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.

LanguageEnglish
Release dateApr 28, 2015
ISBN9781785287275
Git Essentials

Related to Git Essentials

Related ebooks

Software Development & Engineering For You

View More

Related articles

Reviews for Git Essentials

Rating: 4.25 out of 5 stars
4.5/5

4 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Git Essentials - Ferdinando Santacroce

    Table of Contents

    Git Essentials

    Credits

    Foreword

    Foreword

    Foreword

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    Why subscribe?

    Free access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Errata

    Piracy

    Questions

    1. Getting Started with Git

    Installing Git

    Running our first Git command

    Setting up a new repository

    Adding a file

    Commit the added file

    Modify a committed file

    Summary

    2. Git Fundamentals – Working Locally

    Repository structure and file status life cycle

    The working directory

    File statuses

    The staging area

    Unstaging a file

    The time metaphor

    The past

    The present

    The future

    Working with repositories

    Unstaging a file

    Viewing the history

    Anatomy of a commit

    The commit snapshot

    The commit hash

    Author, e-mail, and date

    Commit messages

    Committing a bunch of files

    Ignoring some files and folders by default

    Highlighting an important commit – Git tags

    Taking another way – Git branching

    Anatomy of branches

    Looking at the current branches

    Creating a new branch

    Switching from branch to branch

    Understanding what happens under the hood

    A bird's eye view to branches

    Typing is boring – Git aliases

    Merging branches

    Merge is not the end of the branch

    Exercises

    Exercise 2.1

    What you will learn

    Scenario

    Results

    Exercise 2.2

    What you will learn

    Scenario

    Results

    Deal with branches' modifications

    Diffing branches

    Using a visual diff tool

    Resolving merge conflicts

    Edit collisions

    Resolving a removed file conflict

    Keeping the edited file

    Resolving conflicts by removing the file

    Stashing

    Summary

    3. Git Fundamentals – Working Remotely

    Working with remotes

    Setting up a new GitHub account

    Cloning a repository

    Uploading modifications to remotes

    What do I send to the remote when I push?

    Pushing a new branch to the remote

    The origin

    Tracking branches

    Downloading remote changes

    Checking for modifications and downloading them

    Applying downloaded changes

    Going backward: publish a local repository to GitHub

    Adding a remote to a local repository

    Pushing a local branch to a remote repository

    Social coding – collaborate using GitHub

    Forking a repository

    Submitting pull requests

    Creating a pull request

    Summary

    4. Git Fundamentals – Niche Concepts, Configurations, and Commands

    Dissecting the Git configuration

    Configuration architecture

    Configuration levels

    System level

    Global level

    Repository level

    Listing configurations

    Editing configuration files manually

    Setting up other environment configurations

    Basic configurations

    Typos autocorrection

    Push default

    Defining the default editor

    Other configurations

    Git aliases

    Shortcuts to common commands

    Creating commands

    git unstage

    git undo

    git last

    git difflast

    Advanced aliases with external commands

    Removing an alias

    Aliasing the git command itself

    Git references

    Symbolic references

    Ancestry references

    The first parent

    The second parent

    World-wide techniques

    Changing the last commit message

    Tracing changes in a file

    Cherry picking

    Tricks

    Bare repositories

    Converting a regular repository to a bare one

    Backup repositories

    Archiving the repository

    Bundling the repository

    Summary

    5. Obtaining the Most – Good Commits and Workflows

    The art of committing

    Building the right commit

    Make only one change per commit

    Split up features and tasks

    Write commit messages before starting to code

    Include the whole change in one commit

    Describe the change, not what you have done

    Don't be afraid to commit

    Isolate meaningless commits

    The perfect commit message

    Writing a meaningful subject

    Adding bulleted details lines, when needed

    Tie other useful information

    Special messages for releases

    Conclusions

    Adopting a workflow – a wise act

    Centralized workflows

    How they work

    Feature branch workflow

    GitFlow

    The master branch

    Hotfixes branches

    The develop branch

    The release branch

    The feature branches

    Conclusion

    The GitHub flow

    Anything in the master branch is deployable

    Creating descriptive branches off of the master

    Pushing to named branches constantly

    Opening a pull request at any time

    Merging only after a pull request review

    Deploying immediately after review

    Conclusions

    Other workflows

    The Linux kernel workflow

    Summary

    6. Migrating to Git

    Before starting

    Prerequisites

    Working on a Subversion repository using Git

    Creating a local Subversion repository

    Checking out the Subversion repository with svn client

    Cloning a Subversion repository from Git

    Setting up a local Subversion server

    Adding a tag and a branch

    Committing a file to Subversion using Git as a client

    Using Git with a Subversion repository

    Migrating a Subversion repository

    Retrieving the list of Subversion users

    Cloning the Subversion repository

    Preserving the ignored file list

    Pushing to a local bare Git repository

    Arranging branches and tags

    Renaming the trunk branch to master

    Converting Subversion tags to Git tags

    Pushing the local repository to a remote

    Comparing Git and Subversion commands

    Summary

    7. Git Resources

    Git GUI clients

    Windows

    Git GUI

    TortoiseGit

    GitHub for Windows

    Atlassian SourceTree

    Cmder

    Mac OS X

    Linux

    Building up a personal Git server with web interface

    The SCM Manager

    Learning Git in a visual manner

    Git on the Internet

    Git community on Google+

    GitMinutes and Thomas Ferris Nicolaisen's blog

    Ferdinando Santacroce's blog

    Summary

    Index

    Git Essentials


    Git Essentials

    Copyright © 2015 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: April 2015

    Production reference: 1240415

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78528-790-9

    www.packtpub.com

    Credits

    Author

    Ferdinando Santacroce

    Reviewers

    Fabrizio Donina

    Giovanni Giorgi

    Giovanni Toraldo

    Commissioning Editor

    Edward Gordon

    Acquisition Editor

    Meeta Rajani

    Content Development Editor

    Samantha Gonsalves

    Technical Editor

    Siddhesh Ghadi

    Copy Editors

    Hiral Bhat

    Karuna Narayanan

    Alpha Singh

    Project Coordinator

    Kinjal Bari

    Proofreaders

    Simran Bhogal

    Safis Editing

    Paul Hindle

    Bernadette Watkins

    Indexer

    Tejal Daruwale Soni

    Graphics

    Jason Monteiro

    Abhinash Sahu

    Production Coordinator

    Nilesh R. Mohite

    Cover Work

    Nilesh R. Mohite

    Foreword

    Occasionally, in the IT industry, some inventions are made whose value is far beyond their merely technical merit. Git is one of them.

    Git is immensely faster and more convenient than SVN, CVS, and TFS. It is fast becoming the defacto standard mainly because there are no tools as powerful and versatile as it is; it is a wonderful masterpiece of code. Behind the success of Git lies much more: it is a revolutionary approach to writing code. Git houses an inherently collaborative component in its DNA. It is no coincidence then that the GitHub's tagline is Social Coding.

    If Linus Torvalds goes down in history, it will perhaps be not only for Linux and his genius in writing C, but above all, for the social impact that Git has had on the IT community. Just like the invention of the Web and HTTP have enabled humanity to build a network of communication and collaboration previously unthinkable, Git is the very tool that enables us to transform code development into a social activity. As a matter of fact, Git has started a new era in IT.

    Git is also a very well documented tool. If you want to learn the syntax of its 155 commands, you don't need this book; the man pages, which are available for free on the web, are certainly more exhaustive.

    However, the heart of Git does not lie in the list of its command options. Just like reading the syntax of the class and interface keywords will hardly make you grasp the deeper meaning of object-oriented programming, in the same way, the essence of Git won't emerge easily from its man pages.

    The hardest part of Git is the paradigm shift that it requires. Honestly, very few books that I've read are able to explain Git and the universe that revolves around it, in a simpler way than the one you're holding in your hands.

    This book covers not only all the main topics you can find on the man pages with simplicity and synthesis (such as the commit, stash, rebase, and management of remote), but also has the merit of being one of the few books to give you a 360-degree overview of the ecosystem that every pragmatic programmer should master. It explains how to set up a local server, teaches you the theory and practice behind GitHub and pull requests in a simple and practical way, and even contains a step-by-step guide to migrate from SVN to Git.

    Git Essentials has another merit: it is built like a huge tutorial, and is a step-by-step journey through the Git universe. It's not an academic paper; on the contrary, it's full of concrete examples, is written by a programmer, and targeted at other programmers.

    It is a book that values code much more than words.

    Arialdo Martini

    Solutions Architect at Aduno Gruppe

    Foreword

    At the time of writing this (April 2015), Git has just crossed the historical 10th anniversary since its inception. It is crazy for me to think it's already been 10 years.

    Owing not in a small part to the innovative concepts that Git and some earlier DVCS solutions brought about, a huge chunk of the modern software development world has been turned upside down due to it. Teams that have adopted it have been greatly empowered on many fronts.

    You can branch off and start working on some experimental features without bothering your colleagues. You can also keep your stable branches stable and only merge completed features. Git will also allow you to explore an entire project

    Enjoying the preview?
    Page 1 of 1