Skip to content

Commit 90747c5

Browse files
authored
Reorganize git commands (#263)
* Move the minimal configuration instructions. * Move the remote configuration instructions. * Move the pushing changes and synching remotes sections. * First cleanup pass. * Remove the "Maintaining a repository" section. * Move the "Reverting a Merged Pull Request" section under "Working with Git". * Fix incorrect markup.
1 parent 5657771 commit 90747c5

File tree

4 files changed

+82
-170
lines changed

4 files changed

+82
-170
lines changed

committing.rst

+12-145
Original file line numberDiff line numberDiff line change
@@ -268,23 +268,6 @@ understands the justification for the change). Also, if a non-core developer
268268
contributed to the resolution, it is good practice to credit them.
269269

270270

271-
Reverting a Commit
272-
------------------
273-
274-
To revert a merged pull request, press the ``Revert`` button at the bottom of
275-
the pull request. It will bring up the page to create a new pull request where
276-
the commit can be reverted. It also creates a new branch on the main CPython
277-
repository. Delete the branch once the pull request has been merged.
278-
279-
Always include the reason for reverting the commit to help others understand
280-
why it was done. The reason should be included as part of the commit message,
281-
for example::
282-
283-
Revert bpo-NNNN: Fix Spam Module (GH-111)
284-
285-
Reverts python/cpython#111.
286-
Reason: This commit broke the buildbot.
287-
288271

289272
Working with Git_
290273
=================
@@ -313,107 +296,6 @@ into a state you aren't happy with.
313296
.. _Git: https://git-scm.com/
314297

315298

316-
Minimal Configuration
317-
---------------------
318-
319-
If you use Git as a committer of patches (your own or others), you should
320-
set up some basic options. Here are the minimal options you need to activate:
321-
322-
* Your *name* and *email*: these settings defines what will be used when you
323-
commit changes::
324-
325-
git config --global user.name "Your Name"
326-
git config --global user.email [email protected]
327-
328-
``--global`` flag sets configuration options at a global level, if instead you
329-
want to set it at a project level use ``--local``, instead.
330-
331-
* *Under Windows*, you should also enable the *autocrlf* option, which will
332-
fix any Windows-specific line endings your text editor might insert when you
333-
create or modify versioned files. The public repository has a hook which
334-
will reject all changesets having the wrong line endings, so enabling this
335-
extension on your local computer is in your best interest.
336-
::
337-
338-
git config --global core.autocrlf input
339-
340-
341-
Remotes Setup
342-
-------------
343-
344-
345-
.. _remote-configuration:
346-
347-
Configuration
348-
'''''''''''''
349-
350-
There are several possible ways how to set up your git repository. This section
351-
discusses the simplest approach of having a single directory with two remotes,
352-
one pointing to private fork, the other one being the official repository.
353-
354-
Assuming you have :ref:`cloned the official repository <checkout>` here is how
355-
your current setup should look like::
356-
357-
$ git remote -v # show remotes
358-
origin https://github.com/python/cpython (fetch)
359-
origin https://github.com/python/cpython (push)
360-
361-
You can have multiple remotes defined for a single repository, the usual approach
362-
is to have ``origin`` pointing to your :ref:`private fork <forking>`, and ``upstream``
363-
pointing to the official repository. To do so, here are the steps needed to have
364-
that setup::
365-
366-
git remote set-url origin https://github.com/<your-username>/cpython
367-
git remote add upstream https://github.com/python/cpython
368-
369-
After that, your remotes configuration should look like this::
370-
371-
$ git remote -v # show remotes
372-
origin https://github.com/<your-username>/cpython (fetch)
373-
origin https://github.com/<your-username>/cpython (push)
374-
upstream https://github.com/python/cpython (fetch)
375-
upstream https://github.com/python/cpython (push)
376-
377-
At any point in time you can use SSH-based URL instead of HTTPS-based ones.
378-
379-
380-
.. _committing-push-changes:
381-
382-
Pushing changes
383-
'''''''''''''''
384-
385-
You have two remotes configured (see previous section for setup). Publishing
386-
your changes to any of them is as simple as specifying the name of the remote
387-
upon your push. Assuming I am working on a local branch ``bug1234`` and I want to
388-
push it to my private fork I do::
389-
390-
git push origin bug1234
391-
392-
Option ``-u|--set-upstream`` creates a remote-tracking branch that tracks what
393-
have been pushed to ``origin``::
394-
395-
git push -u origin bug1234
396-
397-
That allows to avoid rebasing beyond already pushed commits.
398-
``git status --branch`` and ``git branch --verbose`` remind that the branch(es)
399-
have not pushed commits.
400-
401-
402-
Synchronizing remotes
403-
'''''''''''''''''''''
404-
405-
To synchronize your fork, from the official repository you need to execute following
406-
commands::
407-
408-
git fetch upstream # fetch remote changes
409-
git checkout master # checkout your current master branch
410-
git merge upstream/master # merge remote changes into your local master branch
411-
git push origin master # publish changes to your private fork
412-
413-
The above steps can be executed against any branch you wish to, just replace master
414-
with an appropriate branch name.
415-
416-
417299
.. _committing-active-branches:
418300

419301
Active branches
@@ -454,34 +336,19 @@ Developers can apply labels to GitHub pull requests).
454336
.. _cherry_picker.py: https://github.com/python/core-workflow/tree/master/cherry_picker
455337

456338

457-
.. _forking:
458-
459-
Forking repository
460-
------------------
461-
462-
Forking a repository on GitHub is as simple as clicking Fork button in the right
463-
upper corner at https://github.com/python/cpython.
464-
339+
Reverting a Merged Pull Request
340+
-------------------------------
465341

466-
Maintaining a repository
467-
------------------------
342+
To revert a merged pull request, press the ``Revert`` button at the bottom of
343+
the pull request. It will bring up the page to create a new pull request where
344+
the commit can be reverted. It also creates a new branch on the main CPython
345+
repository. Delete the branch once the pull request has been merged.
468346

469-
The Git object database and other files/directories under ``.git`` require
470-
periodic maintenance and cleanup. For example, commit editing leaves
471-
unreferenced objects (dangling objects, in git terminology) and these
472-
objects should be pruned to avoid collecting cruft in the DB. The
473-
command ``git gc`` is used for maintenance. Git automatically runs
474-
``git gc --auto`` as a part of some commands to do quick maintenance.
475-
Users are recommended to run ``git gc --aggressive`` from time to
476-
time; ``git help gc`` recommends to run it every few hundred
477-
changesets; for CPython it should be something like once a week
478-
(GitHub itself runs the command weekly, so new checkouts do not need to
479-
perform this step).
347+
Always include the reason for reverting the commit to help others understand
348+
why it was done. The reason should be included as part of the commit message,
349+
for example::
480350

481-
``git gc --aggressive`` not only removes dangling objects, it also
482-
repacks object database into indexed and better optimized pack(s); it
483-
also packs symbolic references (branches and tags).
351+
Revert bpo-NNNN: Fix Spam Module (GH-111)
484352

485-
From time to time run ``git fsck --strict`` to verify integrity of
486-
the database. ``git fsck`` may produce a list of dangling objects;
487-
that's not an error, just a reminder to perform regular maintenance.
353+
Reverts python/cpython#111.
354+
Reason: This commit broke the buildbot.

gitbootcamp.rst

+54-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ relevant to CPython's workflow.
1010

1111
.. contents::
1212

13+
.. _fork-cpython:
1314

1415
Forking CPython GitHub Repository
1516
---------------------------------
@@ -24,24 +25,61 @@ You'll only need to do this once.
2425

2526
4. Your fork will be created at https://github.com/<username>/cpython.
2627

28+
.. _clone-your-fork:
2729

2830
Cloning The Forked CPython Repository
2931
-------------------------------------
3032

3133
You'll only need to do this once. From your command line::
3234

3335
$ git clone [email protected]:<username>/cpython.git
36+
37+
It is also recommended to configure an ``upstream`` remote::
38+
3439
$ cd cpython
3540
$ git remote add upstream [email protected]:python/cpython.git
3641

42+
You can also use SSH-based or HTTPS-based URLs.
3743

3844
Listing the Remote Repositories
3945
-------------------------------
4046

41-
To list the remote repositories that are configured, along with their urls::
47+
To list the remote repositories that are configured, along with their URLs::
4248

4349
$ git remote -v
4450

51+
You should have two remotes: ``origin`` pointing to your fork,
52+
and ``upstream`` pointing to the official CPython repository::
53+
54+
origin [email protected]:<your-username>/devguide.git (fetch)
55+
origin [email protected]:<your-username>/devguide.git (push)
56+
upstream [email protected]:python/devguide.git (fetch)
57+
upstream [email protected]:python/devguide.git (push)
58+
59+
60+
.. _set-up-name-email:
61+
62+
Setting Up Your Name and Email Address
63+
--------------------------------------
64+
::
65+
66+
$ git config --global user.name "Your Name"
67+
$ git config --global user.email [email protected]
68+
69+
The ``--global`` flag sets these globally,
70+
``--local`` sets them only for the current project.
71+
72+
.. _autocrlf:
73+
74+
Enabling ``autocrlf`` on Windows
75+
--------------------------------
76+
77+
The *autocrlf* option will fix automatically any Windows-specific line endings.
78+
This should be enabled on Windows, since the public repository has a hook which
79+
will reject all changesets having the wrong line endings.
80+
::
81+
82+
$ git config --global core.autocrlf input
4583

4684
Creating and Switching Branches
4785
-------------------------------
@@ -139,6 +177,21 @@ To re-apply the last stashed change::
139177

140178
$ git stash pop
141179

180+
.. _commit-changes:
181+
182+
Committing Changes
183+
------------------
184+
185+
Add the files you want to commit::
186+
187+
$ git add <filename>
188+
189+
Commit the files::
190+
191+
$ git commit -m '<message>'
192+
193+
194+
.. _push-changes:
142195

143196
Pushing Changes
144197
---------------

pullrequest.rst

+6-5
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,22 @@ Here is a quick overview of how you can contribute to CPython on GitHub:
107107

108108
#. :ref:`Get started <setup>` and set up your system
109109

110-
#. Fork `CPython`_ on GitHub (using the Fork button in the upper-right on GitHub)
110+
#. :ref:`Fork CPython <fork-cpython>` (using the Fork button in the
111+
upper-right on GitHub)
112+
113+
#. :ref:`Clone your GitHub fork and add an "upstream" remote <clone-your-fork>`
111114

112115
#. :ref:`Build Python <compiling>` on your system
113116

114117
#. :ref:`Run tests <runtests>` after you have built Python
115118

116-
#. :ref:`Add an "upstream" Remote in Git <remote-configuration>` (using SSH,
117-
or you can `use HTTPS`_)
118-
119119
#. :ref:`Create a Branch in Git <pullrequest-steps>` where you can work on
120120
changes
121121

122122
#. :ref:`Run tests <runtests>` again
123123

124-
#. :ref:`Push commits <committing-push-changes>` to your GitHub repo
124+
#. :ref:`Commit <commit-changes>` and :ref:`push <push-changes>`
125+
changes to your GitHub fork
125126

126127
#. `Create Pull Request`_ on GitHub to merge a branch from your fork
127128

setup.rst

+10-19
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,27 @@ installation directions. You may also want to consider a graphical client
3434
such as `TortoiseGit <https://tortoisegit.org/>`_ or
3535
`GitHub Desktop <https://desktop.github.com/>`_.
3636

37-
You may also wish to
38-
`set up an SSH key <https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/>`_
37+
You may also wish to set up :ref:`your name and email <set-up-name-email>`
38+
and `an SSH key
39+
<https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/>`_
3940
as this will allow you to interact with GitHub without typing a username
4041
and password each time you execute a command, such as ``git pull``,
41-
``git push``, or ``git fetch``.
42-
42+
``git push``, or ``git fetch``. On Windows, you should also
43+
:ref:`enable autocrlf <autocrlf>`.
4344

4445
.. _checkout:
4546

4647
Getting the Source Code
4748
-----------------------
4849

49-
One should always work from a working copy of the CPython source code.
50-
While it may
51-
be tempting to work from the copy of Python you already have installed on your
52-
machine, it is very likely that you will be working from out-of-date code as
53-
the Python core developers are constantly updating and fixing things in their
54-
:abbr:`VCS (version control system)`. It also means you will have better tool
55-
support through the VCS as it will provide a diff tool, etc.
56-
57-
To get a working copy of the :ref:`in-development <indevbranch>` branch of
58-
CPython, run::
59-
60-
git clone https://github.com/python/cpython
50+
In order to get a copy of the source code you should first :ref:`fork the
51+
Python repository on GitHub <fork-cpython>` and then :ref:`create a local
52+
clone of your private fork and configure the remotes <clone-your-fork>`.
6153

6254
If you want a working copy of an already-released version of Python,
6355
i.e., a version in :ref:`maintenance mode <maintbranch>`, you can checkout
64-
a release branch. For instance, to checkout a working copy of Python 3.5, do::
65-
66-
git checkout 3.5
56+
a release branch. For instance, to checkout a working copy of Python 3.5,
57+
do ``git checkout 3.5``.
6758

6859
You will need to re-compile CPython when you do such an update.
6960

0 commit comments

Comments
 (0)