You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/01-introduction/1-introduction.asc
+48-42Lines changed: 48 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
[[_getting_started]]
1
2
== Getting Started
2
3
3
4
This chapter will be about getting started with Git.
@@ -6,7 +7,7 @@ At the end of this chapter you should understand why Git is around, why you shou
6
7
7
8
=== About Version Control (((version control)))
8
9
9
-
What is ((("version control"))), and why should you care?
10
+
What is "version control", and why should you care?
10
11
Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.
11
12
For the examples in this book you will use software source code as the files being version controlled, though in reality you can do this with nearly any type of file on a computer.
12
13
@@ -34,7 +35,7 @@ RCS works by keeping patch sets (that is, the differences between files) in a sp
34
35
35
36
The next major issue that people encounter is that they need to collaborate with developers on other systems.
36
37
To deal with this problem, Centralized Version Control Systems (CVCSs) were developed.
37
-
These systems, such as CVS, Subversion, and Perforce, have a single server that contains all the versioned files, and a number of clients that check out files from that central place.
38
+
These systems, such as CVS, Subversion, and Perforce, have a single server that contains all the versioned files, and a number of clients that check out files from that central place. (((CVS)))(((Subversion)))(((Perforce)))
38
39
For many years, this has been the standard for version control.
39
40
40
41
.Centralized version control.
@@ -67,19 +68,19 @@ This allows you to set up several types of workflows that aren’t possible in c
67
68
68
69
As with many great things in life, Git began with a bit of creative destruction and fiery controversy.
69
70
70
-
The Linux kernel is an open source software project of fairly large scope.
71
+
The Linux kernel is an open source software project of fairly large scope.(((Linux)))
71
72
For most of the lifetime of the Linux kernel maintenance (1991–2002), changes to the software were passed around as patches and archived files.
72
-
In 2002, the Linux kernel project began using a proprietary DVCS called BitKeeper.
73
+
In 2002, the Linux kernel project began using a proprietary DVCS called BitKeeper.(((BitKeeper)))
73
74
74
75
In 2005, the relationship between the community that developed the Linux kernel and the commercial company that developed BitKeeper broke down, and the tool’s free-of-charge status was revoked.
75
-
This prompted the Linux development community (and in particular Linus Torvalds, the creator of Linux) to develop their own tool based on some of the lessons they learned while using BitKeeper.
76
+
This prompted the Linux development community (and in particular Linus Torvalds, the creator of Linux) to develop their own tool based on some of the lessons they learned while using BitKeeper.(((Linus Torvalds)))
76
77
Some of the goals of the new system were as follows:
77
78
78
79
* Speed
79
80
* Simple design
80
81
* Strong support for non-linear development (thousands of parallel branches)
81
82
* Fully distributed
82
-
* Able to handle large projects like the Linux kernel efficiently (speed and data size)
83
+
* Able to handle large projects like the Linux kernel efficiently (speed and data size)(((Linux)))
83
84
84
85
Since its birth in 2005, Git has evolved and matured to be easy to use and yet retain these initial qualities.
85
86
It’s incredibly fast, it’s very efficient with large projects, and it has an incredible branching system for non-linear development (See <<_git_branching>>).
@@ -89,7 +90,7 @@ It’s incredibly fast, it’s very efficient with large projects, and it has an
89
90
So, what is Git in a nutshell?
90
91
This is an important section to absorb, because if you understand what Git is and the fundamentals of how it works, then using Git effectively will probably be much easier for you.
91
92
As you learn Git, try to clear your mind of the things you may know about other VCSs, such as Subversion and Perforce; doing so will help you avoid subtle confusion when using the tool.
92
-
Git stores and thinks about information much differently than these other systems, even though the user interface is fairly similar, and understanding those differences will help prevent you from becoming confused while using it.
93
+
Git stores and thinks about information much differently than these other systems, even though the user interface is fairly similar, and understanding those differences will help prevent you from becoming confused while using it.(((Subversion)))(((Perforce)))
93
94
94
95
==== Snapshots, Not Differences
95
96
@@ -138,7 +139,7 @@ This means it’s impossible to change the contents of any file or directory wit
138
139
This functionality is built into Git at the lowest levels and is integral to its philosophy.
139
140
You can’t lose information in transit or get file corruption without Git being able to detect it.
140
141
141
-
The mechanism that Git uses for this checksumming is called a SHA-1 hash.
142
+
The mechanism that Git uses for this checksumming is called a SHA-1 hash.(((SHA-1)))
142
143
This is a 40-character string composed of hexadecimal characters (0–9 and a–f) and calculated based on the contents of a file or directory structure in Git.
143
144
A SHA-1 hash looks something like this:
144
145
@@ -208,23 +209,23 @@ Before you start using Git, you have to make it available on your computer.
208
209
Even if it's already installed, it's probably a good idea to update to the latest version.
209
210
You can either install it as a package or via another installer, or download the source code and compile it yourself.
210
211
211
-
==== Installing on Linux
212
+
==== Installing on Linux(((Linux, installing)))
212
213
213
214
If you want to install Git on Linux via a binary installer, you can generally do so through the basic package-management tool that comes with your distribution.
214
-
If you’re on Fedora, you can use yum:
215
+
If you’re on Fedora for example, you can use yum:
215
216
216
217
$ yum install git
217
218
218
-
Or if you’re on a Debian-based distribution like Ubuntu, try apt-get:
219
+
If you’re on a Debian-based distribution like Ubuntu, try apt-get:
219
220
220
221
$ apt-get install git
221
222
222
223
For more options, there are instructions for installing on several different Unix flavors on the Git website, at http://git-scm.com/download/linux[].
223
224
224
-
==== Installing on Mac
225
+
==== Installing on Mac(((Mac, installing)))
225
226
226
227
There are several ways to install Git on a Mac.
227
-
The easiest is probably to install the Xcode Command Line Tools.
228
+
The easiest is probably to install the Xcode Command Line Tools.(((Xcode)))
228
229
On Mavericks (10.9) or above you can do this simply by trying to run 'git' from the Terminal the very first time.
229
230
If you don't have it installed already, it will prompt you to install it.
230
231
@@ -240,37 +241,16 @@ You can download that tool from the GitHub for Mac website, at http://mac.github
240
241
241
242
==== Installing on Windows
242
243
243
-
There are also a few ways to install Git on Windows.
244
+
There are also a few ways to install Git on Windows.(((Windows, installing)))
244
245
The most official build is available for download on the Git website.
245
246
Just go to http://git-scm.com/download/win[] and the download will start automatically.
246
247
Note that this is a project called Git for Windows (also called msysGit), which is separate from Git itself; for more information on it, go to http://msysgit.github.io/[].
247
248
248
-
249
249
Another easy way to get Git installed is by installing GitHub for Windows.
250
250
The installer includes a command line version of Git as well as the GUI.
251
251
It also works well with Powershell, and sets up solid credential caching and sane CRLF settings.
252
252
We'll learn more about those things a little later, but suffice it to say they're things you want.
253
253
254
-
=== First-Time Git Setup
255
-
256
-
Now that you have Git on your system, you’ll want to do a few things to customize your Git environment.
257
-
You should have to do these things only once on any given computer; they’ll stick around between upgrades.
258
-
You can also change them at any time by running through the commands again.
259
-
260
-
Git comes with a tool called `git config` that lets you get and set configuration variables that control all aspects of how Git looks and operates.
261
-
These variables can be stored in three different places:
262
-
263
-
1. `/etc/gitconfig` file: Contains values for every user on the system and all their repositories.
264
-
If you pass the option` --system` to `git config`, it reads and writes from this file specifically.
265
-
2. `~/.gitconfig` or `~/.config/git/config` file: Specific to your user.
266
-
You can make Git read and write to this file specifically by passing the `--global` option.
267
-
3. `config` file in the Git directory (that is, `.git/config`) of whatever repository you’re currently using: Specific to that single repository.
268
-
269
-
Each level overrides values in the previous level, so values in `.git/config` trump those in `/etc/gitconfig`.
270
-
271
-
On Windows systems, Git looks for the `.gitconfig` file in the `$HOME` directory (`C:\Users\$USER` for most people).
272
-
It also still looks for `/etc/gitconfig`, although it’s relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.
273
-
274
254
==== Installing from Source
275
255
276
256
Some people may instead find it useful to install Git from source, because you’ll get the most recent version.
@@ -302,27 +282,53 @@ After this is done, you can also get Git via Git itself for updates:
Now that you have Git on your system, you’ll want to do a few things to customize your Git environment.
289
+
You should have to do these things only once on any given computer; they’ll stick around between upgrades.
290
+
You can also change them at any time by running through the commands again.
291
+
292
+
Git comes with a tool called `git config` that lets you get and set configuration variables that control all aspects of how Git looks and operates.(((git, config)))
293
+
These variables can be stored in three different places:
294
+
295
+
1. `/etc/gitconfig` file: Contains values for every user on the system and all their repositories.
296
+
If you pass the option` --system` to `git config`, it reads and writes from this file specifically.
297
+
2. `~/.gitconfig` or `~/.config/git/config` file: Specific to your user.
298
+
You can make Git read and write to this file specifically by passing the `--global` option.
299
+
3. `config` file in the Git directory (that is, `.git/config`) of whatever repository you’re currently using: Specific to that single repository.
300
+
301
+
Each level overrides values in the previous level, so values in `.git/config` trump those in `/etc/gitconfig`.
302
+
303
+
On Windows systems, Git looks for the `.gitconfig` file in the `$HOME` directory (`C:\Users\$USER` for most people).
304
+
It also still looks for `/etc/gitconfig`, although it’s relative to the MSys root, which is wherever you decide to install Git on your Windows system when you run the installer.
305
+
305
306
==== Your Identity
306
307
307
308
The first thing you should do when you install Git is to set your user name and e-mail address.
308
-
This is important because every Git commit uses this information, and it’s immutably baked into the commits you pass around:
309
+
This is important because every Git commit uses this information, and it’s immutably baked into the commits you start creating:
Again, you need to do this only once if you pass the `--global` option, because then Git will always use that information for anything you do on that system.
314
315
If you want to override this with a different name or e-mail address for specific projects, you can run the command without the `--global` option when you’re in that project.
315
316
316
-
Many of the GUI tools will help you do this when you first run them as well.
317
+
Many of the GUI tools will help you do this when you first run them.
317
318
318
319
==== Your Editor
319
320
320
321
Now that your identity is set up, you can configure the default text editor that will be used when Git needs you to type in a message.
321
-
By default, Git uses your system’s default editor, which is generally vi or Vim.
322
+
If not configured, Git uses your system’s default editor, which is generally Vim.
322
323
If you want to use a different text editor, such as Emacs, you can do the following:
323
324
324
325
$ git config --global core.editor emacs
325
326
327
+
[NOTE]
328
+
====
329
+
Vim and Emacs are popular text editors often used by developers on Unix based systems like Linux and Mac. If you are not familiar with either of these editors or are on a Windows system, you may need to search for instructions for how to set up your favorite editor with Git.
330
+
====
331
+
326
332
==== Checking Your Settings
327
333
328
334
If you want to check your settings, you can use the `git config --list` command to list all the settings Git can find at that point:
@@ -339,7 +345,7 @@ If you want to check your settings, you can use the `git config --list` command
339
345
You may see keys more than once, because Git reads the same key from different files (`/etc/gitconfig` and `~/.gitconfig`, for example).
340
346
In this case, Git uses the last value for each unique key it sees.
341
347
342
-
You can also check what Git thinks a specific key’s value is by typing `git config <key>`:
348
+
You can also check what Git thinks a specific key’s value is by typing `git config <key>`:(((git, config)))
343
349
344
350
$ git config user.name
345
351
John Doe
@@ -352,16 +358,16 @@ If you ever need help while using Git, there are three ways to get the manual pa
352
358
$ git <verb> --help
353
359
$ man git-<verb>
354
360
355
-
For example, you can get the manpage help for the config command by running
361
+
For example, you can get the manpage help for the config command by running(((git, help)))
356
362
357
363
$ git help config
358
364
359
365
These commands are nice because you can access them anywhere, even offline.
360
366
If the manpages and this book aren’t enough and you need in-person help, you can try the `#git` or `#github` channel on the Freenode IRC server (irc.freenode.net).
361
-
These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.
367
+
These channels are regularly filled with hundreds of people who are all very knowledgeable about Git and are often willing to help.(((IRC)))
362
368
363
369
=== Summary
364
370
365
-
You should have a basic understanding of what Git is and how it’s different from the CVCS you may have been using.
371
+
You should have a basic understanding of what Git is and how it’s different from the centralized version control system you may have previously been using.
366
372
You should also now have a working version of Git on your system that’s set up with your personal identity.
0 commit comments