Skip to content

Commit

Permalink
pythongh-890: Use git switch to switch to branch (python#905)
Browse files Browse the repository at this point in the history
* pythongh-890 Use git switch to switch to branch

instead of using git checkout

python#890

* pythongh-890 Update gitbootcamp.rst

replace "git checkout <branch-name>" with "git switch <branch-name>"

* pythongh-890 Add new command ``git switch`` on setup.rst

* Remove mentions of the checkout command.

* Use `switch -c` instead of `checkout -b`.

Co-authored-by: Ezio Melotti <[email protected]>
  • Loading branch information
za and ezio-melotti authored Jun 23, 2022
1 parent 960c453 commit ab2fd9b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
23 changes: 11 additions & 12 deletions gitbootcamp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,16 @@ Creating and Switching Branches
.. important::
Never commit directly to the ``main`` branch.

Create a new branch and switch to it::
Create a new branch from ``main`` and switch to it::

# creates a new branch off main and switch to it
git checkout -b <branch-name> main
git switch -c <branch-name> main

This is equivalent to::

# create a new branch from main, without checking it out
# create a new branch from main
git branch <branch-name> main
# check out the branch
git checkout <branch-name>
# switch to the new branch
git switch <branch-name>

To find the branch you are currently on::

Expand All @@ -128,12 +127,12 @@ To list all the branches, including the remote branches::

To switch to a different branch::

git checkout <another-branch-name>
git switch <another-branch-name>

Other releases are just branches in the repository. For example, to work
on the 2.7 release from the ``upstream`` remote::

git checkout -b 2.7 upstream/2.7
git switch -c 2.7 upstream/2.7

.. _deleting_branches:

Expand All @@ -142,7 +141,7 @@ Deleting Branches

To delete a **local** branch that you no longer need::

git checkout main
git switch main
git branch -D <branch-name>

To delete a **remote** branch::
Expand Down Expand Up @@ -262,7 +261,7 @@ them to the remote repository.

::

git checkout <branch-name>
git switch <branch-name>
git push origin <branch-name>

Creating a Pull Request
Expand Down Expand Up @@ -299,7 +298,7 @@ get notified unnecessarily.

Solution::

git checkout main
git switch main
git pull upstream main
git push origin main

Expand All @@ -317,7 +316,7 @@ Another scenario:

Solution::

git checkout some-branch
git switch some-branch
git fetch upstream
git merge upstream/main
git push origin some-branch
Expand Down
4 changes: 2 additions & 2 deletions pullrequest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ You should have already :ref:`set up your system <setup>`,
to your branch, making more changes, committing them, and pushing them to
automatically update your PR::

git checkout <branch-name>
git switch <branch-name>
# make changes and run tests
git add <filenames>
git commit -m '<message>'
Expand All @@ -129,7 +129,7 @@ You should have already :ref:`set up your system <setup>`,
will show a warning to this end and you may be asked to address this. Merge
the changes from the main branch while resolving the conflicts locally::

git checkout <branch-name>
git switch <branch-name>
git pull upstream main # pull = fetch + merge
# resolve conflicts: see "Resolving Merge Conflicts" below
git push origin <branch-name>
Expand Down
2 changes: 1 addition & 1 deletion setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ in the ``cpython`` directory and two remotes that refer to your own GitHub fork
If you want a working copy of an already-released version of Python,
i.e., a version in :ref:`maintenance mode <maintbranch>`, you can checkout
a release branch. For instance, to checkout a working copy of Python 3.8,
do ``git checkout 3.8``.
do ``git switch 3.8``.

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

Expand Down

0 comments on commit ab2fd9b

Please sign in to comment.