Git Pocket Guide
Richard E. Silverman
Beijing Cambridge Farnham Kln Sebastopol Tokyo
Download from Wow! eBook
Special Upgrade Offer
If you purchased this ebook directly from oreilly.com, you have the following benefits:
DRM-free ebooksuse your ebooks across devices without restrictions or limitations
Multiple formatsuse on your laptop, tablet, or phone
Lifetime access, with free updates
Dropbox syncingyour files, anywhere
If you purchased this ebook from another retailer, you can upgrade your ebook to take advantage of all these benefits for just $4.99. to access your ebook upgrade.
Please note that upgrade offers are not available from sample content.
Preface
What Is Git?
Git is a tool for tracking changes made to a set of files over time, a task traditionally known as version control. Although it is most often used by programmers to coordinate changes to software source code, and it is especially good at that, you can use Git to track any kind of content at all. Any body of related files evolving over time, which well call a project, is a candidate for using Git. With Git, you can:
- Examine the state of your project at earlier points in time
- Show the differences among various states of the project
- Split the project development into multiple independent lines, called branches, which can evolve separately
- Periodically recombine branches in a process called merging, reconciling the changes made in two or more branches
- Allow many people to work on a project simultaneously, sharing and combining their work as needed
and much more.
There have been many different version control systems developed in the computing world, including SCCS, RCS, CVS, Subversion, BitKeeper, Mercurial, Bazaar, Darcs, and others. Some particular strengths of Git are:
- Git is a member of the newer generation of distributed version control systems. Older systems such as CVS and Subversion are centralized , meaning that there is a single, central copy of the project content and history to which all users must refer. Typically accessed over a network, if the central copy is unavailable for some reason, all users are stuck; they cannot use version control until the central copy is working again. Distributed systems such as Git, on the other hand, have no inherent central copy. Each user has a complete, independent copy of the entire project history, called a repository, and full access to all version control facilities. Network access is only needed occasionally, to share sets of changes among people working on the same project.
- In some systems, notably CVS and Subversion, branches are slow and difficult to use in practice, which discourages their use. Branches in Git, on the other hand, are very fast and easy to use. Effective branching and merging allows more people to work on a project in parallel, relying on Git to combine their separate contributions.
- Applying changes to a repository is a two-step process: you add the changes to a staging area called the index, then commit those changes to the repository. The extra step allows you to easily apply just some of the changes in your current working files (including a subset of changes to a single file), rather than being forced to apply them all at once, or undoing some of those changes yourself before committing and then redoing them by hand. This encourages splitting changes up into better organized, more coherent and reusable sets.
- Gits distributed nature and flexibility allow for many different styles of use, or workflows. Individuals can share work directly between their personal repositories. Groups can coordinate their work through a single central repository. Hybrid schemes permit several people to organize the contributions of others to different areas of a project, and then collaborate among themselves to maintain the overall project state.
- Git is the technology behind the enormously popular social coding website GitHub, which includes many well-known open source projects. In learning Git, you will open up a whole world of collaboration on small and large scales.
Goals of This Book
There are already several good books available on Git, including Scott Chacons Pro Git , and the full-size Version Control with Git by Jon Loeliger (OReilly). In addition, the Git software documentation (man pages on Unix) is generally well written and complete. So, why a Git Pocket Guide ? The primary goal of this book is to provide a compact, readable introduction to Git for the new user, as well as a reference to common commands and procedures that will continue to be useful once youve already gotten some Git under your belt. The man pages are extensive and very detailed; sometimes, its difficult to peruse them for just the information you need for simple operations, and you may need to refer to several different sections to pull together the pieces you need. The two books mentioned are similarly weighty tomes with a wealth of detail. This Pocket Guide is task oriented, organized around the basic functions you need from version control: making commits, fixing mistakes, merging, searching history, and so on. It also contains a streamlined technical introduction whose aim is to make sense of Git generally and facilitate understanding of the operations discussed, rather than completeness or depth for its own sake. The intent is to help you become productive with Git quickly and easily.
Since this book does not aim to be a complete reference to all of Gits capabilities, there are Git commands and functions that we do not discuss. We often mention these omissions explicitly, but some are tacit. Several more advanced features are just mentioned and described briefly so that youre aware of their existence, with a pointer to the relevant documentation. Also, the sections that cover specific commands usually do not list every possible option or mode of operation, but rather the most common or useful ones that fit into the discussion at hand. The goal is simplicity and economy of explanation, rather than exhaustive detail. We do provide frequent references to various portions of the Git documentation, where you can find more complete information on the current topic. This book should be taken as an introduction, an aid to understanding, and a complement to the full documentation, rather than as a replacement for it.
At the time of this writing in early 2013, Git is undergoing rapid development; new versions appear regularly with new features and changes to existing ones, so expect that by the time you read this, some alterations will already have occurred; thats just the nature of technical writing. This book describes Git as of version 1.8.2.
Conventions Used in This Book
Here are a few general remarks and conventions to keep in mind while reading this book.
Unix
Git was created in the Unix environment, originally in fact both for and by people working on the core of the Linux operating system. Though it has been ported to other platforms, it is still most popular on Unix variants, and its commands, design, and terminology all strongly reflect its origin. Especially in a Pocket Guide format, it would be distracting to have constant asides on minor differences with other platforms, so for simplicity and uniformity, this book assumes Unix generally in its descriptions and choice of examples.