Preface |
|
xvii | |
About this Book |
|
xix | |
Acknowledgments |
|
xxii | |
|
|
1 | (7) |
|
1.1 What makes Git so special? |
|
|
1 | (2) |
|
1.2 Is this book for you? |
|
|
3 | (1) |
|
|
3 | (1) |
|
|
4 | (1) |
|
|
5 | (2) |
|
|
7 | (1) |
|
1.7 Being immediately effective |
|
|
7 | (1) |
|
2 An overview of Git and version control |
|
|
8 | (17) |
|
2.1 Version control concepts |
|
|
8 | (6) |
|
Version control for the software developer |
|
|
8 | (1) |
|
Version control for the organization |
|
|
9 | (1) |
|
|
10 | (1) |
|
|
11 | (1) |
|
|
12 | (2) |
|
|
14 | (3) |
|
|
15 | (1) |
|
|
16 | (1) |
|
|
17 | (1) |
|
|
17 | (7) |
|
Using the GUI to tour a Git repository |
|
|
18 | (3) |
|
Using the command line to tour a Git repository |
|
|
21 | (3) |
|
2.4 Version control terminology |
|
|
24 | (1) |
|
3 Getting oriented with Git |
|
|
25 | (11) |
|
|
25 | (2) |
|
|
27 | (3) |
|
|
27 | (1) |
|
|
28 | (2) |
|
3.3 Improving command-line efficiency |
|
|
30 | (1) |
|
|
31 | (2) |
|
3.5 Controlling long output with a pager |
|
|
33 | (1) |
|
|
34 | (1) |
|
|
34 | (1) |
|
3.8 Commands in this chapter |
|
|
35 | (1) |
|
4 Making and using a Git repository |
|
|
36 | (11) |
|
4.1 Understanding repository basics |
|
|
36 | (1) |
|
4.2 Creating a new repository with git init |
|
|
37 | (2) |
|
4.3 Tracking files with git status and git add |
|
|
39 | (3) |
|
Using git status to check your repository state |
|
|
39 | (2) |
|
Using git add to add a file to your repository |
|
|
41 | (1) |
|
4.4 Committing files with git commit |
|
|
42 | (2) |
|
4.5 Viewing the repository with git log and ls-files |
|
|
44 | (1) |
|
|
45 | (1) |
|
4.7 Commands in this chapter |
|
|
46 | (1) |
|
|
47 | (14) |
|
|
47 | (2) |
|
Starting Git GUI in Windows |
|
|
48 | (1) |
|
5.2 Creating a repository with Git GUI |
|
|
49 | (2) |
|
5.3 Adding a file into the repository via Git GUI |
|
|
51 | (6) |
|
5.4 Looking at your history |
|
|
57 | (1) |
|
|
58 | (1) |
|
|
59 | (1) |
|
|
59 | (1) |
|
|
59 | (1) |
|
5.7 Commands in this chapter |
|
|
60 | (1) |
|
6 Tracking and updating files in Git |
|
|
61 | (15) |
|
6.1 Making simple changes |
|
|
61 | (4) |
|
Creating a new repository |
|
|
61 | (1) |
|
Telling Git about changes |
|
|
62 | (1) |
|
|
63 | (1) |
|
Adding and committing changes to the repo |
|
|
64 | (1) |
|
6.2 Thinking about git add |
|
|
65 | (7) |
|
An analogy to introduce the staging area |
|
|
65 | (1) |
|
Adding changes to the staging area |
|
|
66 | (1) |
|
Updating the staging area |
|
|
66 | (1) |
|
Understanding the staging area |
|
|
67 | (3) |
|
|
70 | (2) |
|
6.3 Adding multiple files |
|
|
72 | (2) |
|
|
74 | (1) |
|
Understanding command-line nuances |
|
|
74 | (1) |
|
|
74 | (1) |
|
|
74 | (1) |
|
|
74 | (1) |
|
6.6 Commands in this chapter |
|
|
75 | (1) |
|
7 Committing parts of changes |
|
|
76 | (22) |
|
7.1 Deleting files from Git |
|
|
76 | (2) |
|
7.2 Renaming files in Git |
|
|
78 | (3) |
|
7.3 Adding directories into your repository |
|
|
81 | (2) |
|
7.4 Adding parts of changes |
|
|
83 | (13) |
|
Reconsidering the stage analogy |
|
|
83 | (1) |
|
Considering when to commit |
|
|
84 | (2) |
|
Committing parts of a file by using Git GUI |
|
|
86 | (4) |
|
Committing parts of a file using git add p |
|
|
90 | (3) |
|
Removing changes from the staging area |
|
|
93 | (1) |
|
Resetting a file to the last committed version |
|
|
94 | (1) |
|
Understanding consequences of partial commits |
|
|
95 | (1) |
|
|
96 | (1) |
|
Working with multiple hunks |
|
|
96 | (1) |
|
Changing your mind with a delete |
|
|
97 | (1) |
|
|
97 | (1) |
|
7.6 Commands in this chapter |
|
|
97 | (1) |
|
8 The time machine that is Git |
|
|
98 | (21) |
|
|
98 | (7) |
|
|
99 | (1) |
|
Exploring meta information |
|
|
100 | (2) |
|
Using gitk to view the commit history |
|
|
102 | (2) |
|
Finding all commits by file |
|
|
104 | (1) |
|
Using variations of git log |
|
|
104 | (1) |
|
8.2 Making proper commit log messages |
|
|
105 | (2) |
|
8.3 Checking out a specific version |
|
|
107 | (7) |
|
Understanding HEAD, master, and other names |
|
|
108 | (2) |
|
Going back in time with git checkout |
|
|
110 | (4) |
|
8.4 Breadcrumbs to previous versions |
|
|
114 | (1) |
|
|
115 | (2) |
|
|
115 | (1) |
|
|
116 | (1) |
|
|
116 | (1) |
|
Committing while in detached HEAD mode |
|
|
116 | (1) |
|
|
117 | (1) |
|
|
117 | (1) |
|
|
117 | (1) |
|
8.7 Commands in this chapter |
|
|
117 | (2) |
|
9 Taking a fork in the road |
|
|
119 | (21) |
|
|
119 | (4) |
|
|
120 | (1) |
|
Understanding that master is just a convention |
|
|
121 | (2) |
|
9.2 When and how to create branches |
|
|
123 | (8) |
|
Introducing new code with branches |
|
|
123 | (7) |
|
Introducing fixes with branches |
|
|
130 | (1) |
|
9.3 Performing other branch operations |
|
|
131 | (3) |
|
|
131 | (1) |
|
|
132 | (2) |
|
9.4 Switching branches safely |
|
|
134 | (2) |
|
|
134 | (1) |
|
|
135 | (1) |
|
|
136 | (2) |
|
Using the GUI for branch work |
|
|
136 | (1) |
|
|
137 | (1) |
|
Working on another_fix_branch |
|
|
137 | (1) |
|
|
138 | (1) |
|
|
138 | (1) |
|
9.7 Commands in this chapter |
|
|
139 | (1) |
|
|
140 | (20) |
|
10.1 Considering point of view: Traffic merges into us |
|
|
141 | (1) |
|
|
141 | (7) |
|
Starting with at least two branches |
|
|
141 | (2) |
|
Checking the difference between two branches |
|
|
143 | (1) |
|
|
144 | (2) |
|
Working with a merge commit's parents |
|
|
146 | (1) |
|
Performing merges in Git GUI |
|
|
147 | (1) |
|
10.3 Handling merge conflicts |
|
|
148 | (6) |
|
Understanding differences that Git can't handle |
|
|
148 | (2) |
|
Merging files by directly editing conflicting hunks |
|
|
150 | (1) |
|
Merging files by using a merge tool |
|
|
151 | (3) |
|
|
154 | (1) |
|
10.4 Performing fast-forward merges |
|
|
154 | (3) |
|
Understanding the direct-descendant concept |
|
|
154 | (2) |
|
Making a fast-forward merge |
|
|
156 | (1) |
|
|
157 | (1) |
|
|
158 | (1) |
|
Calculating the base of a merge with git merge-base |
|
|
158 | (1) |
|
Changing how conflicts are displayed (merge.conflictstyle) |
|
|
158 | (1) |
|
Performing octopus merges |
|
|
158 | (1) |
|
10.7 Commands in this chapter |
|
|
159 | (1) |
|
|
160 | (17) |
|
11.1 Cloning: making copies locally |
|
|
160 | (7) |
|
|
161 | (2) |
|
Viewing branches in your clone |
|
|
163 | (3) |
|
|
166 | (1) |
|
11.2 Working with the bare directory |
|
|
167 | (6) |
|
Examining Git repository files |
|
|
168 | (1) |
|
Creating bare directories with git clone |
|
|
168 | (2) |
|
Cloning from bare directories |
|
|
170 | (3) |
|
11.3 Listing files in the repo by using git ls-tree |
|
|
173 | (1) |
|
|
174 | (1) |
|
|
175 | (1) |
|
11.6 Commands in this chapter |
|
|
176 | (1) |
|
12 Collaborating with remotes |
|
|
177 | (15) |
|
12.1 Remotes are distant places |
|
|
177 | (7) |
|
Analyzing a clone's origin (git remote) |
|
|
179 | (1) |
|
|
180 | (2) |
|
|
182 | (2) |
|
12.2 Interrogating a remote |
|
|
184 | (4) |
|
12.3 Getting a clone from somewhere remote |
|
|
188 | (1) |
|
|
189 | (1) |
|
Exploring your math.github clone |
|
|
189 | (1) |
|
|
189 | (1) |
|
Using other git remote subcommands |
|
|
190 | (1) |
|
Creating clones with Git GUI |
|
|
190 | (1) |
|
Accessing another remote URL |
|
|
190 | (1) |
|
|
190 | (1) |
|
12.6 Commands in this chapter |
|
|
191 | (1) |
|
|
192 | (22) |
|
13.1 Pushing sends changes to a remote |
|
|
193 | (7) |
|
|
193 | (1) |
|
Pushing requires a branch and a remote |
|
|
194 | (2) |
|
Verifying a successful git push |
|
|
196 | (4) |
|
13.2 Understanding push conflicts |
|
|
200 | (2) |
|
|
202 | (4) |
|
13.4 Deleting branches on the remote |
|
|
206 | (2) |
|
13.5 Pushing and deleting tags |
|
|
208 | (1) |
|
13.6 Configuring simple pushes |
|
|
209 | (1) |
|
|
210 | (1) |
|
|
211 | (1) |
|
13.9 Commands in this chapter |
|
|
212 | (2) |
|
|
214 | (25) |
|
14.1 Completing the cycle of collaboration |
|
|
214 | (4) |
|
14.2 Using git pull: a two-part operation |
|
|
218 | (7) |
|
Fetching files from a remote repository (git fetch) |
|
|
219 | (5) |
|
Merging two branches (git merge) |
|
|
224 | (1) |
|
|
225 | (10) |
|
|
226 | (1) |
|
Clean merge with nonautomatic commit |
|
|
227 | (3) |
|
Clean merge with automatic commit |
|
|
230 | (1) |
|
|
231 | (4) |
|
14.4 Restricting pulls to fast-forwards only |
|
|
235 | (1) |
|
14.5 Using git fetch and merge instead of pull |
|
|
236 | (1) |
|
|
237 | (1) |
|
14.7 Commands in this chapter |
|
|
238 | (1) |
|
|
239 | (22) |
|
15.1 Understanding git log |
|
|
239 | (9) |
|
Reviewing the basics of git log |
|
|
239 | (2) |
|
Limiting the display of commits |
|
|
241 | (3) |
|
Seeing differences with git log |
|
|
244 | (2) |
|
Using git name-rev to name commits |
|
|
246 | (2) |
|
15.2 Understanding gitk view configurations |
|
|
248 | (3) |
|
Showing only specific branches in gitk |
|
|
248 | (2) |
|
Working with simplified views |
|
|
250 | (1) |
|
|
251 | (4) |
|
Finding files of interest (git grep) |
|
|
251 | (1) |
|
Examining the history of one file |
|
|
252 | (3) |
|
15.4 Finding which revision updated a specific line of code |
|
|
255 | (2) |
|
Running git blame as a GUI |
|
|
255 | (2) |
|
Using git blame on the command line |
|
|
257 | (1) |
|
15.5 Leaving messages for those who follow |
|
|
257 | (1) |
|
|
258 | (1) |
|
|
258 | (2) |
|
15.8 Commands in this chapter |
|
|
260 | (1) |
|
16 Understanding git rebase |
|
|
261 | (18) |
|
16.1 Examining two git rebase use cases |
|
|
262 | (2) |
|
Keeping up with the upstream by using git rebase |
|
|
262 | (1) |
|
Cleaning up history by using git rebase |
|
|
263 | (1) |
|
16.2 Examining use case 1: keeping up with the upstream |
|
|
264 | (3) |
|
16.3 Using git reflog and git reset to revert your repo |
|
|
267 | (3) |
|
16.4 Examining use case 2: cleaning up history |
|
|
270 | (5) |
|
|
275 | (1) |
|
|
276 | (2) |
|
|
276 | (1) |
|
|
277 | (1) |
|
16.7 Commands in this chapter |
|
|
278 | (1) |
|
17 Workflows and branching conventions |
|
|
279 | (14) |
|
17.1 The need for Git conventions |
|
|
279 | (2) |
|
|
280 | (1) |
|
Conventions for pushing code |
|
|
280 | (1) |
|
Conventions for branching |
|
|
281 | (1) |
|
Conventions for using rebase |
|
|
281 | (1) |
|
|
281 | (1) |
|
|
281 | (1) |
|
|
282 | (6) |
|
|
283 | (3) |
|
|
286 | (2) |
|
|
288 | (2) |
|
|
290 | (1) |
|
|
290 | (2) |
|
17.7 Commands in this chapter |
|
|
292 | (1) |
|
|
293 | (18) |
|
18.1 Understanding GitHub basics |
|
|
293 | (7) |
|
Creating a GitHub account |
|
|
295 | (1) |
|
|
296 | (1) |
|
Interacting with the repository |
|
|
297 | (3) |
|
|
300 | (3) |
|
|
300 | (2) |
|
|
302 | (1) |
|
18.3 Collaborating with pull requests |
|
|
303 | (5) |
|
Making a change to your fork |
|
|
304 | (1) |
|
|
305 | (2) |
|
|
307 | (1) |
|
|
308 | (1) |
|
|
309 | (1) |
|
18.6 Commands in this chapter |
|
|
310 | (1) |
|
19 Third-party tools and Git |
|
|
311 | (17) |
|
|
311 | (8) |
|
|
312 | (1) |
|
Adding a repository into SourceTree |
|
|
313 | (2) |
|
|
315 | (1) |
|
Tracking underlying Git commands in SourceTree |
|
|
316 | (2) |
|
Committing a file in SourceTree |
|
|
318 | (1) |
|
|
318 | (1) |
|
19.2 Git and the Eclipse IDE |
|
|
319 | (7) |
|
|
320 | (1) |
|
Adding a repository into Eclipse |
|
|
320 | (2) |
|
Staging and committing a file |
|
|
322 | (3) |
|
|
325 | (1) |
|
19.3 Other third-party tools |
|
|
326 | (1) |
|
|
327 | (1) |
|
|
328 | (17) |
|
20.1 Introducing the git config command |
|
|
328 | (5) |
|
Using Git configuration variables |
|
|
328 | (1) |
|
Understanding Git configuration order of precedence |
|
|
329 | (2) |
|
Setting Git configurations temporarily |
|
|
331 | (1) |
|
Setting Git configurations permanently |
|
|
332 | (1) |
|
Resetting Git configurations |
|
|
333 | (1) |
|
20.2 Working with Git configuration files |
|
|
333 | (3) |
|
Editing Git configuration files |
|
|
333 | (1) |
|
Using Git configuration file syntax |
|
|
334 | (2) |
|
20.3 Configuring Git's default editor |
|
|
336 | (3) |
|
20.4 Configuring files to ignore |
|
|
339 | (2) |
|
20.5 Continually learning Git |
|
|
341 | (1) |
|
|
341 | (1) |
|
|
341 | (1) |
|
|
342 | (1) |
|
|
342 | (1) |
|
|
342 | (2) |
|
20.7 Commands in this chapter |
|
|
344 | (1) |
index |
|
345 | |