@@ -32,12 +32,12 @@ Cloning The Forked CPython Repository
32
32
33
33
You'll only need to do this once. From your command line::
34
34
35
- $ git clone [email protected] :<username>/cpython.git
35
+ git clone [email protected] :<username>/cpython.git
36
36
37
37
It is also recommended to configure an ``upstream `` remote::
38
38
39
- $ cd cpython
40
- $ git remote add upstream [email protected] :python/cpython.git
39
+ cd cpython
40
+ git remote add upstream [email protected] :python/cpython.git
41
41
42
42
You can also use SSH-based or HTTPS-based URLs.
43
43
@@ -46,7 +46,7 @@ Listing the Remote Repositories
46
46
47
47
To list the remote repositories that are configured, along with their URLs::
48
48
49
- $ git remote -v
49
+ git remote -v
50
50
51
51
You should have two remotes: ``origin `` pointing to your fork,
52
52
and ``upstream `` pointing to the official CPython repository::
@@ -61,10 +61,11 @@ and ``upstream`` pointing to the official CPython repository::
61
61
62
62
Setting Up Your Name and Email Address
63
63
--------------------------------------
64
- ::
65
64
66
- $ git config --global user.name "Your Name"
67
- $ git config --global user.email [email protected]
65
+ .. code-block :: bash
66
+
67
+ git config --global user.name " Your Name"
68
+ git config --global user.email [email protected]
68
69
69
70
The ``--global `` flag sets these globally,
70
71
``--local `` sets them only for the current project.
@@ -78,7 +79,7 @@ The *autocrlf* option will fix automatically any Windows-specific line endings.
78
79
This should be enabled on Windows, since the public repository has a hook which
79
80
will reject all changesets having the wrong line endings::
80
81
81
- $ git config --global core.autocrlf input
82
+ git config --global core.autocrlf input
82
83
83
84
Creating and Switching Branches
84
85
-------------------------------
@@ -89,34 +90,34 @@ Creating and Switching Branches
89
90
Create a new branch and switch to it::
90
91
91
92
# creates a new branch off master and switch to it
92
- $ git checkout -b <branch-name> master
93
+ git checkout -b <branch-name> master
93
94
94
95
This is equivalent to::
95
96
96
97
# create a new branch off 'master', without checking it out
97
- $ git branch <branch-name> master
98
+ git branch <branch-name> master
98
99
# check out the branch
99
- $ git checkout <branch-name>
100
+ git checkout <branch-name>
100
101
101
102
To find the branch you are currently on::
102
103
103
- $ git branch
104
+ git branch
104
105
105
106
The current branch will have an asterisk next to the branch name. Note, this
106
107
will only list all of your local branches.
107
108
108
109
To list all the branches, including the remote branches::
109
110
110
- $ git branch -a
111
+ git branch -a
111
112
112
113
To switch to a different branch::
113
114
114
- $ git checkout <another-branch-name>
115
+ git checkout <another-branch-name>
115
116
116
117
Other releases are just branches in the repository. For example, to work
117
118
on the 2.7 release::
118
119
119
- $ git checkout -b 2.7 origin/2.7
120
+ git checkout -b 2.7 origin/2.7
120
121
121
122
122
123
.. _deleting_branches :
@@ -126,12 +127,12 @@ Deleting Branches
126
127
127
128
To delete a **local ** branch that you no longer need::
128
129
129
- $ git checkout master
130
- $ git branch -D <branch-name>
130
+ git checkout master
131
+ git branch -D <branch-name>
131
132
132
133
To delete a **remote ** branch::
133
134
134
- $ git push origin -d <branch-name>
135
+ git push origin -d <branch-name>
135
136
136
137
You may specify more than one branch for deletion.
137
138
@@ -141,40 +142,42 @@ Staging and Committing Files
141
142
142
143
1. To show the current changes::
143
144
144
- $ git status
145
+ git status
145
146
146
147
2. To stage the files to be included in your commit::
147
148
148
- $ git add path/to/file1 path/to/file2 path/to/file3
149
+ git add path/to/file1 path/to/file2 path/to/file3
149
150
150
- 3. To commit the files that have been staged (done in step 2)::
151
+ 3. To commit the files that have been staged (done in step 2):
151
152
152
- $ git commit -m "bpo-XXXX: This is the commit message."
153
+ .. code-block :: bash
154
+
155
+ git commit -m " bpo-XXXX: This is the commit message."
153
156
154
157
155
158
Reverting Changes
156
159
-----------------
157
160
158
161
To revert changes to a file that has not been committed yet::
159
162
160
- $ git checkout path/to/file
163
+ git checkout path/to/file
161
164
162
165
If the change has been committed, and now you want to reset it to whatever
163
166
the origin is at::
164
167
165
- $ git reset --hard HEAD
168
+ git reset --hard HEAD
166
169
167
170
168
171
Stashing Changes
169
172
----------------
170
173
171
174
To stash away changes that are not ready to be committed yet::
172
175
173
- $ git stash
176
+ git stash
174
177
175
178
To re-apply the last stashed change::
176
179
177
- $ git stash pop
180
+ git stash pop
178
181
179
182
.. _commit-changes :
180
183
@@ -183,11 +186,13 @@ Committing Changes
183
186
184
187
Add the files you want to commit::
185
188
186
- $ git add <filename>
189
+ git add <filename>
190
+
191
+ Commit the files:
187
192
188
- Commit the files::
193
+ .. code-block :: bash
189
194
190
- $ git commit -m '<message>'
195
+ git commit -m ' <message>'
191
196
192
197
193
198
.. _push-changes :
@@ -200,8 +205,8 @@ them to the remote repository.
200
205
201
206
::
202
207
203
- $ git checkout <branch-name>
204
- $ git push origin <branch-name>
208
+ git checkout <branch-name>
209
+ git push origin <branch-name>
205
210
206
211
207
212
Creating a Pull Request
@@ -235,9 +240,9 @@ Scenario:
235
240
236
241
Solution::
237
242
238
- $ git checkout master
239
- $ git pull --rebase upstream master
240
- $ git push origin master
243
+ git checkout master
244
+ git pull --rebase upstream master
245
+ git push origin master
241
246
242
247
The ``--rebase `` option is only needed if you have local changes to the
243
248
branch.
@@ -252,10 +257,10 @@ Another scenario:
252
257
253
258
Solution::
254
259
255
- $ git checkout some-branch
256
- $ git fetch upstream
257
- $ git rebase upstream/master
258
- $ git push --force origin some-branch
260
+ git checkout some-branch
261
+ git fetch upstream
262
+ git rebase upstream/master
263
+ git push --force origin some-branch
259
264
260
265
261
266
.. _git_from_mercurial :
@@ -273,13 +278,15 @@ Solution:
273
278
274
279
2. Apply the patch::
275
280
276
- $ git apply /path/to/issueNNNN-git.patch
281
+ git apply /path/to/issueNNNN-git.patch
277
282
278
283
If there are errors, update to a revision from when the patch was
279
- created and then try the ``git apply`` again::
284
+ created and then try the ``git apply`` again:
280
285
281
- $ git checkout `git rev-list -n 1 --before="yyyy-mm-dd hh:mm:ss" master`
282
- $ git apply /path/to/issueNNNN-git.patch
286
+ .. code-block:: bash
287
+
288
+ git checkout `git rev-list -n 1 --before="yyyy-mm-dd hh:mm:ss" master`
289
+ git apply /path/to/issueNNNN-git.patch
283
290
284
291
If the patch still won't apply, then a patch tool will not be able to
285
292
apply the patch and it will need to be re-implemented manually.
@@ -291,8 +298,8 @@ Solution:
291
298
5. If the patch was applied to an old revision, it needs to be updated and
292
299
merge conflicts need to be resolved::
293
300
294
- $ git rebase master
295
- $ git mergetool
301
+ git rebase master
302
+ git mergetool
296
303
297
304
6. Push the changes and open a pull request.
298
305
@@ -312,14 +319,16 @@ On Unix and MacOS, set up the following git alias::
312
319
313
320
$ git config --global alias.pr '!sh -c "git fetch upstream pull/${1}/head:pr_${1} && git checkout pr_${1}" -'
314
321
315
- On Windows, reverse the single (`' `) and double (`" `) quotes::
322
+ On Windows, reverse the single (`' `) and double (`" `) quotes:
323
+
324
+ .. code-block :: bash
316
325
317
326
git config --global alias.pr " !sh -c 'git fetch upstream pull/${1} /head:pr_${1} && git checkout pr_${1} ' -"
318
327
319
328
The alias only needs to be done once. After the alias is set up, you can get a
320
329
local copy of a pull request as follows::
321
330
322
- $ git pr <pr_number>
331
+ git pr <pr_number>
323
332
324
333
325
334
.. _accepting-and-merging-a-pr :
@@ -378,10 +387,12 @@ page. Find the event that says something like::
378
387
By following the link to ``<commit_sha1> ``, you will get the full commit hash.
379
388
380
389
Alternatively, the commit hash can also be obtained by the following git
381
- commands::
390
+ commands:
382
391
383
- $ git fetch upstream
384
- $ git rev-parse ":/bpo-12345"
392
+ .. code-block :: bash
393
+
394
+ git fetch upstream
395
+ git rev-parse " :/bpo-12345"
385
396
386
397
The above commands will print out the hash of the commit containing
387
398
``"bpo-12345" `` as part of the commit message.
@@ -425,21 +436,23 @@ To edit an open pull request that targets ``master``:
425
436
426
437
2. Fetch the pull request, using the :ref: `git pr <git_pr >` alias::
427
438
428
- $ git pr <pr_number>
439
+ git pr <pr_number>
429
440
430
441
This will checkout the contributor's branch at ``pr_XXX``.
431
442
432
443
3. Make and commit your changes on the branch. For example, merge in changes
433
444
made to ``master `` since the PR was submitted (any merge commits will be
434
- removed by the later ``Squash and Merge `` when accepting the change)::
445
+ removed by the later ``Squash and Merge `` when accepting the change):
446
+
447
+ .. code-block :: bash
435
448
436
- $ git fetch upstream
437
- $ git merge upstream/master
438
- $ git add <filename>
439
- $ git commit -m "<commit message>"
449
+ git fetch upstream
450
+ git merge upstream/master
451
+ git add < filename>
452
+ git commit -m " <commit message>"
440
453
441
454
4. Push the changes back to the contributor's PR branch::
442
455
443
- $ git push [email protected] :<contributor>/cpython <pr_XXX>:<branch_name>
456
+ git push [email protected] :<contributor>/cpython <pr_XXX>:<branch_name>
444
457
445
458
5. Optionally, :ref: `delete the PR branch <deleting_branches >`.
0 commit comments