@@ -18,7 +18,7 @@ Git Bootcamp and Cheat Sheet
18
18
desire a different approach.
19
19
20
20
21
- In this section, we'll go over some commonly used Git commands that are
21
+ In this section, we will go over some commonly used Git commands that are
22
22
relevant to CPython's workflow.
23
23
24
24
.. note ::
@@ -33,26 +33,26 @@ relevant to CPython's workflow.
33
33
Forking CPython GitHub Repository
34
34
---------------------------------
35
35
36
- You'll only need to do this once.
36
+ You will only need to do this once.
37
37
38
38
1. Go to https://github.com/python/cpython.
39
39
40
40
2. Press ``Fork `` on the top right.
41
41
42
42
3. When asked where to fork the repository, choose to fork it to your username.
43
43
44
- 4. Your fork will be created at https://github.com/<username>/cpython.
44
+ 4. Your forked CPython repository will be created at https://github.com/<username>/cpython.
45
45
46
46
.. _clone-your-fork :
47
47
48
- Cloning The Forked CPython Repository
49
- -------------------------------------
48
+ Cloning a Forked CPython Repository
49
+ -----------------------------------
50
50
51
- You'll only need to do this once. From your command line::
51
+ You will only need to do this once. From your command line::
52
52
53
53
git clone git@github.com:<username>/cpython.git
54
54
55
- It is also recommended to configure an ``upstream `` remote::
55
+ It is also recommended to configure an ``upstream `` remote repository ::
56
56
57
57
cd cpython
58
58
git remote add upstream git@github.com:python/cpython.git
@@ -66,11 +66,11 @@ To list the remote repositories that are configured, along with their URLs::
66
66
67
67
git remote -v
68
68
69
- You should have two remotes : ``origin `` pointing to your fork ,
69
+ You should have two remote repositories : ``origin `` pointing to your forked CPython repository ,
70
70
and ``upstream `` pointing to the official CPython repository::
71
71
72
- origin git@github.com:<your- username>/cpython.git (fetch)
73
- origin git@github.com:<your- username>/cpython.git (push)
72
+ origin git@github.com:<username>/cpython.git (fetch)
73
+ origin git@github.com:<username>/cpython.git (push)
74
74
upstream git@github.com:python/cpython.git (fetch)
75
75
upstream git@github.com:python/cpython.git (push)
76
76
@@ -83,17 +83,17 @@ Setting Up Your Name and Email Address
83
83
.. code-block :: bash
84
84
85
85
git config --global user.name " Your Name"
86
- git config --global user.email email@example.org
86
+ git config --global user.email your. email@example.com
87
87
88
- The ``--global `` flag sets these globally,
89
- ``--local `` sets them only for the current project.
88
+ The ``--global `` flag sets these parameters globally while
89
+ the ``--local `` flag sets them only for the current project.
90
90
91
91
.. _autocrlf :
92
92
93
93
Enabling ``autocrlf `` on Windows
94
94
--------------------------------
95
95
96
- The * autocrlf * option will fix automatically any Windows-specific line endings.
96
+ The `` autocrlf `` option will fix automatically any Windows-specific line endings.
97
97
This should be enabled on Windows, since the public repository has a hook which
98
98
will reject all changesets having the wrong line endings::
99
99
@@ -112,7 +112,7 @@ Create a new branch and switch to it::
112
112
113
113
This is equivalent to::
114
114
115
- # create a new branch off ' master' , without checking it out
115
+ # create a new branch from master, without checking it out
116
116
git branch <branch-name> master
117
117
# check out the branch
118
118
git checkout <branch-name>
@@ -137,7 +137,6 @@ on the 2.7 release from the ``upstream`` remote::
137
137
138
138
git checkout -b 2.7 upstream/2.7
139
139
140
-
141
140
.. _deleting_branches :
142
141
143
142
Deleting Branches
@@ -154,7 +153,6 @@ To delete a **remote** branch::
154
153
155
154
You may specify more than one branch for deletion.
156
155
157
-
158
156
Staging and Committing Files
159
157
----------------------------
160
158
@@ -164,28 +162,26 @@ Staging and Committing Files
164
162
165
163
2. To stage the files to be included in your commit::
166
164
167
- git add path/to/file1 path/to/file2 path/to/file3
165
+ git add <filename1> <filename2>
168
166
169
167
3. To commit the files that have been staged (done in step 2):
170
168
171
169
.. code-block :: bash
172
170
173
171
git commit -m " bpo-XXXX: This is the commit message."
174
172
175
-
176
173
Reverting Changes
177
174
-----------------
178
175
179
176
To revert changes to a file that has not been committed yet::
180
177
181
- git checkout path/to/file
178
+ git checkout <filename>
182
179
183
180
If the change has been committed, and now you want to reset it to whatever
184
181
the origin is at::
185
182
186
183
git reset --hard HEAD
187
184
188
-
189
185
Stashing Changes
190
186
----------------
191
187
@@ -210,51 +206,48 @@ Commit the files:
210
206
211
207
.. code-block :: bash
212
208
213
- git commit -m ' <message>'
214
-
209
+ git commit -m " <message>"
215
210
216
211
.. _push-changes :
217
212
F438
218
213
Pushing Changes
219
214
---------------
220
215
221
- Once your changes are ready for a review or a pull request, you'll need to push
216
+ Once your changes are ready for a review or a pull request, you will need to push
222
217
them to the remote repository.
223
218
224
219
::
225
220
226
221
git checkout <branch-name>
227
222
git push origin <branch-name>
228
223
229
-
230
224
Creating a Pull Request
231
225
-----------------------
232
226
233
227
1. Go to https://github.com/python/cpython.
234
228
235
- 2. Press ``New pull request `` button.
229
+ 2. Press the ``New pull request `` button.
236
230
237
- 3. Click ``compare across forks `` link.
231
+ 3. Click the ``compare across forks `` link.
238
232
239
- 4. Select the base fork : ``python/cpython `` and base branch: ``master ``.
233
+ 4. Select the base repository : ``python/cpython `` and base branch: ``master ``.
240
234
241
- 5. Select the head fork : ``<username>/cpython `` and base branch: the branch
235
+ 5. Select the head repository : ``<username>/cpython `` and head branch: the branch
242
236
containing your changes.
243
237
244
- 6. Press ``Create Pull Request `` button.
238
+ 6. Press the ``Create pull request `` button.
245
239
246
-
247
- Syncing With Upstream
240
+ Syncing with Upstream
248
241
---------------------
249
242
250
243
Scenario:
251
244
252
245
- You forked the CPython repository some time ago.
253
246
- Time passes.
254
- - There have been new commits made in upstream CPython repository.
247
+ - There have been new commits made in the upstream CPython repository.
255
248
- Your forked CPython repository is no longer up to date.
256
249
- You now want to update your forked CPython repository to be the same as
257
- upstream.
250
+ the upstream CPython repository .
258
251
259
252
Solution::
260
253
@@ -267,8 +260,9 @@ Another scenario:
267
260
- You created ``some-branch `` some time ago.
268
261
- Time passes.
269
262
- You made some commits to ``some-branch ``.
270
- - Meanwhile, there are recent changes from upstream CPython repository.
271
- - You want to incorporate the recent changes from upstream into ``some-branch ``.
263
+ - Meanwhile, there are recent changes from the upstream CPython repository.
264
+ - You want to incorporate the recent changes from the upstream CPython
265
+ repository into ``some-branch ``.
272
266
273
267
Solution::
274
268
@@ -282,9 +276,8 @@ you run ``git merge upstream/master``.
282
276
283
277
When it happens, you need to resolve conflict. See these articles about resolving conflicts:
284
278
285
- * `About merge conflicts <https://help.github.com/en/articles/about-merge-conflicts >`_
286
- * `Resolving a merge conflict using the command line <https://help.github.com/en/articles/resolving-a-merge-conflict-using-the-command-line >`_
287
-
279
+ - `About merge conflicts <https://help.github.com/en/articles/about-merge-conflicts >`_
280
+ - `Resolving a merge conflict using the command line <https://help.github.com/en/articles/resolving-a-merge-conflict-using-the-command-line >`_
288
281
289
282
.. _git_from_mercurial :
290
283
@@ -326,8 +319,6 @@ Solution:
326
319
327
320
6. Push the changes and open a pull request.
328
321
329
-
330
-
331
322
.. _git_pr :
332
323
333
324
Downloading Other's Patches
@@ -342,7 +333,7 @@ On Unix and MacOS, set up the following git alias::
342
333
343
334
$ git config --global alias.pr '!sh -c "git fetch upstream pull/${1}/head:pr_${1} && git checkout pr_${1}" -'
344
335
345
- On Windows, reverse the single (`' ` ) and double (`" `) quotes:
336
+ On Windows, reverse the single (`` ' `` ) and double (`` " ` `) quotes:
346
337
347
338
.. code-block :: bash
348
339
@@ -362,10 +353,9 @@ local copy of a pull request as follows::
362
353
So you can ``git push `` if the pull request author checked
363
354
"Allow edits from maintainers" when creating the pull request.
364
355
365
-
366
356
.. _accepting-and-merging-a-pr :
367
357
368
- Accepting and Merging A Pull Request
358
+ Accepting and Merging a Pull Request
369
359
------------------------------------
370
360
371
361
Pull requests can be accepted and merged by a Python Core Developer.
@@ -399,8 +389,7 @@ Pull requests can be accepted and merged by a Python Core Developer.
399
389
`How to Write a Git Commit Message <https://chris.beams.io/posts/git-commit/ >`_
400
390
is a nice article describing how to write a good commit message.
401
391
402
- 3. Press the ``Confirm squash and merge `` button.
403
-
392
+ 4. Press the ``Confirm squash and merge `` button.
404
393
405
394
Backporting Merged Changes
406
395
--------------------------
@@ -418,7 +407,7 @@ The commit hash for backporting is the squashed commit that was merged to
418
407
the ``master `` branch. On the merged pull request, scroll to the bottom of the
419
408
page. Find the event that says something like::
420
409
421
- <coredeveloper > merged commit <commit_sha1> into python:master <sometime> ago.
410
+ <core_developer > merged commit <commit_sha1> into python:master <sometime> ago.
422
411
423
412
By following the link to ``<commit_sha1> ``, you will get the full commit hash.
424
413
@@ -466,15 +455,15 @@ items like updating ``Misc/ACKS``.
466
455
To edit an open pull request that targets ``master ``:
467
456
468
457
1. In the pull request page, under the description, there is some information
469
- about the contributor's fork and branch name that will be useful later::
458
+ about the contributor's forked CPython repository and branch name that will be useful later::
470
459
471
460
<contributor> wants to merge 1 commit into python:master from <contributor>:<branch_name>
472
461
473
462
2. Fetch the pull request, using the :ref: `git pr <git_pr >` alias::
474
463
475
464
git pr <pr_number>
476
465
477
- This will checkout the contributor's branch at ``pr_XXX ``.
466
+ This will checkout the contributor's branch at ``<pr_number> ``.
478
467
479
468
3. Make and commit your changes on the branch. For example, merge in changes
480
469
made to ``master `` since the PR was submitted (any merge commits will be
@@ -485,10 +474,10 @@ To edit an open pull request that targets ``master``:
485
474
git fetch upstream
486
475
git merge upstream/master
487
476
git add < filename>
488
- git commit -m " <commit message>"
477
+ git commit -m " <message>"
489
478
490
479
4. Push the changes back to the contributor's PR branch::
491
480
492
- git push git@github.com:<contributor>/cpython <pr_XXX >:<branch_name>
481
+ git push git@github.com:<contributor>/cpython <pr_number >:<branch_name>
493
482
494
483
5. Optionally, :ref: `delete the PR branch <deleting_branches >`.
0 commit comments