Você está na página 1de 20

www.it-ebooks.

info

This work is licensed under the Creative Commons Attribution- NonCommercial-ShareAlike 3.0 Unported License.
To view a copy of this li- cense, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative

Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

www.it-ebooks.info

Preface

Welcome to the second edition of Pro Git. The first edition was published over four years ago now. Since then a lot
has changed and yet many important things have not. While most of the core commands and concepts are still valid
today as the Git core team is pretty fantastic at keeping things backward com- patible, there have been some
significant additions and changes in the commu- nity surrounding Git. The second edition of this book is meant to
address those changes and update the book so it can be more helpful to the new user.
When I wrote the first edition, Git was still a relatively difficult to use and barely adopted tool for the harder core
hacker. It was starting to gain steam in certain communities, but had not reached anywhere near the ubiquity it has
to- day. Since then, nearly every open source community has adopted it. Git has made incredible progress on
Windows, in the explosion of graphical user inter- faces to it for all platforms, in IDE support and in business use. The
Pro Git of four years ago knows about none of that. One of the main aims of this new edi- tion is to touch on all of
those new frontiers in the Git community.
The Open Source community using Git has also exploded. When I originally sat down to write the book nearly five
years ago (it took me a while to get the first version out), I had just started working at a very little known company developing a Git hosting website called GitHub. At the time of publishing there were maybe a few thousand people
using the site and just four of us working on it. As I write this introduction, GitHub is announcing our 10 millionth
hosted project, with nearly 5 million registered developer accounts and over 230 em- ployees. Love it or hate it,
GitHub has heavily changed large swaths of the Open Source community in a way that was barely conceivable when
I sat down to write the first edition.
I wrote a small section in the original version of Pro Git about GitHub as an example of hosted Git which I was
never very comfortable with. I didnt much like that I was writing what I felt was essentially a community resource and
also talking about my company in it. While I still dont love that conflict of interests, the importance of GitHub in the Git
community is unavoidable. Instead of an example of Git hosting, I have decided to turn that part of the book into more
deeply describing what GitHub is and how to effectively use it. If you are going to learn how to use Git then knowing
how to use GitHub will help you take part

iii www.it-ebooks.info

Preface
in a huge community, which is valuable no matter which Git host you decide to use for your own code.

The other large change in the time since the last publishing has been the de- velopment and rise of the HTTP
protocol for Git network transactions. Most of the examples in the book have been changed to HTTP from SSH
because its so much simpler.
Its been amazing to watch Git grow over the past few years from a relatively obscure version control system to
basically dominating commercial and open source version control. Im happy that Pro Git has done so well and has
also been able to be one of the few technical books on the market that is both quite successful and fully open source.
I hope you enjoy this updated edition of Pro Git.
iv

www.it-ebooks.info

Contributors

Since this is an Open Source book, we have gotten several errata and content changes donated over the years. Here
are all the people who have contributed to the English version of Pro Git as an open source project. Thank you
everyone for helping make this a better book for everyone.
2 Aaron Schumacher 4 Aggelos Orfanakos 4 Alec Clews 1 Alex Moundalexis 2 Alexander Harkness 1 Alexander
Kahn 1 Andrew McCarthy 1 AntonioK 1 Benjamin Bergman 1 Brennon Bortz 2 Brian P O'Rourke 1 Bryan Goines 1
Cameron Wright 1 Chris Down 1 Christian Kluge 1 Christoph Korn 2 Ciro Santilli 2 Cor 1 Dan Croak 1 Dan Johnson 1
Daniel Kay 2 Daniel Rosen 1 DanielWeber 1 Dave Dash 10 Davide Fiorentino lo Regio
2 Dilip M 1 Dimitar Bonev 1 Emmanuel Trillaud 1 Eric-Paul Lecluse 1 Eugene Serkin 1 Fernando Dobladez 2 Gordon
McCreight 1 Helmut K. C. Tessarek

v www.it-ebooks.info

Contributors
31 Igor Murzov

1 Ilya Kuznetsov 1 Jason St. John 1 Jay Taggart 1 Jean Jordaan 51 Jean-Nol Avila
1 Jean-Nol Rouvignac 1 Jed Hartman 1 Jeffrey Forman 1 John DeStefano 1 Junior 1 Kieran Spear 1 Larry Shatzer,
Jr 1 Linquize 1 Markus 7 Matt Deacalion Stevens 1 Matthew McCullough 1 Matthieu Moy 1 Max F. Albrecht 1 Michael
Schneider 8 Mike D. Smith 1 Mike Limansky 1 Olivier Trichet 1 Ondrej Novy 6 Ori Avtalion 1 Paul Baumgart 1 Peter
Vojtek 1 Philipp Kempgen 2 Philippe Lhoste 1 PowerKiKi 1 Radek Simko 1 Rasmus Abrahamsen 1 Reinhard Holler 1
Ross Light 1 Ryuichi Okumura 1 Sebastian Wiesinger 1 Severyn Kozak 1 Shane 2 Shannen 8 Sitaram Chamarty 5
Soon Van 4 Sven Axelsson 2 Tim Court 1 Tuomas Suutari 1 Vlad Gorodetsky 3 W. Trevor King 1 Wyatt Carss 1
Wodzimierz Gajda 1 Xue Fuqiao 1 Yue Lin Ho
vi

www.it-ebooks.info

Contributors
2 adelcambre 1 anaran 1 bdukes 1 burningTyger 1 cor 1 iosias 7 nicesw123 1 onovy 2 pcasaretto 1 sampablokuper

vii www.it-ebooks.info

www.it-ebooks.info

Introduction

Youre about to spend several hours of your life reading about Git. Lets take a minute to explain what we have in
store for you. Here is a quick summary of the ten chapters and three appendices of this book.
In Chapter 1, were going to cover Version Control Systems (VCSs) and Git basicsno technical stuff, just what
Git is, why it came about in a land full of VCSs, what sets it apart, and why so many people are using it. Then, well
ex- plain how to download Git and set it up for the first time if you dont already have it on your system.
In Chapter 2, we will go over basic Git usagehow to use Git in the 80% of cases youll encounter most often.
After reading this chapter, you should be able to clone a repository, see what has happened in the history of the
project, modify files, and contribute changes. If the book spontaneously combusts at this point, you should already be
pretty useful wielding Git in the time it takes you to go pick up another copy.
Chapter 3 is about the branching model in Git, often described as Gits killer feature. Here youll learn what truly
sets Git apart from the pack. When youre done, you may feel the need to spend a quiet moment pondering how you
lived before Git branching was part of your life.
Chapter 4 will cover Git on the server. This chapter is for those of you who want to set up Git inside your
organization or on your own personal server for collaboration. We will also explore various hosted options if you
prefer to let someone else handle that for you.
Chapter 5 will go over in full detail various distributed workflows and how to accomplish them with Git. When you
are done with this chapter, you should be able to work expertly with multiple remote repositories, use Git over e-mail
and deftly juggle numerous remote branches and contributed patches.
Chapter 6 covers the GitHub hosting service and tooling in depth. We cover signing up for and managing an
account, creating and using Git repositories, common workflows to contribute to projects and to accept contributions
to yours, GitHubs programmatic interface and lots of little tips to make your life easier in general.
Chapter 7 is about advanced Git commands. Here you will learn about top- ics like mastering the scary reset
command, using binary search to identify

ix www.it-ebooks.info

Introduction
bugs, editing history, revision selection in detail, and a lot more. This chapter will round out your knowledge of Git so

that you are truly a master.


Chapter 8 is about configuring your custom Git environment. This includes setting up hook scripts to enforce or
encourage customized policies and using environment configuration settings so you can work the way you want to.
We will also cover building your own set of scripts to enforce a custom committing policy.
Chapter 9 deals with Git and other VCSs. This includes using Git in a Subver- sion (SVN) world and converting
projects from other VCSs to Git. A lot of organi- zations still use SVN and are not about to change, but by this point
youll have learned the incredible power of Gitand this chapter shows you how to cope if you still have to use a
SVN server. We also cover how to import projects from several different systems in case you do convince everyone
to make the plunge. Chapter 10 delves into the murky yet beautiful depths of Git internals. Now that you know all
about Git and can wield it with power and grace, you can move on to discuss how Git stores its objects, what the
object model is, details of packfiles, server protocols, and more. Throughout the book, we will refer to sections of this
chapter in case you feel like diving deep at that point; but if you are like me and want to dive into the technical details,
you may want to read Chapter 10 first. We leave that up to you.
In Appendix A we look at a number of examples of using Git in various spe- cific environments. We cover a
number of different GUIs and IDE programming environments that you may want to use Git in and what is available
for you. If youre interested in an overview of using Git in your shell, in Visual Studio or Eclipse, take a look here.
In Appendix B we explore scripting and extending Git through tools like lib- git2 and JGit. If youre interested in
writing complex and fast custom tools and need low level Git access, this is where you can see what that landscape
looks like.
Finally in Appendix C we go through all the major Git commands one at a time and review where in the book we
covered them and what we did with them. If you want to know where in the book we used any specific Git command
you can look that up here.
Lets get started.
x

www.it-ebooks.info

Você também pode gostar