Skip to content

Commit ab2fd9b

Browse files
zaezio-melotti
andauthored
gh-890: Use git switch to switch to branch (#905)
* gh-890 Use git switch to switch to branch instead of using git checkout #890 * gh-890 Update gitbootcamp.rst replace "git checkout <branch-name>" with "git switch <branch-name>" * gh-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 <ezio.melotti@gmail.com>
1 parent 960c453 commit ab2fd9b

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

gitbootcamp.rst

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,16 @@ Creating and Switching Branches
103103
.. important::
104104
Never commit directly to the ``main`` branch.
105105

106-
Create a new branch and switch to it::
106+
Create a new branch from ``main`` and switch to it::
107107

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

111110
This is equivalent to::
112111

113-
# create a new branch from main, without checking it out
112+
# create a new branch from main
114113
git branch <branch-name> main
115-
# check out the branch
116-
git checkout <branch-name>
114+
# switch to the new branch
115+
git switch <branch-name>
117116

118117
To find the branch you are currently on::
119118

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

129128
To switch to a different branch::
130129

131-
git checkout <another-branch-name>
130+
git switch <another-branch-name>
132131

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

136-
git checkout -b 2.7 upstream/2.7
135+
git switch -c 2.7 upstream/2.7
137136

138137
.. _deleting_branches:
139138

@@ -142,7 +141,7 @@ Deleting Branches
142141

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

145-
git checkout main
144+
git switch main
146145
git branch -D <branch-name>
147146

148147
To delete a **remote** branch::
@@ -262,7 +261,7 @@ them to the remote repository.
262261

263262
::
264263

265-
git checkout <branch-name>
264+
git switch <branch-name>
266265
git push origin <branch-name>
267266

268267
Creating a Pull Request
@@ -299,7 +298,7 @@ get notified unnecessarily.
299298

300299
Solution::
301300

302-
git checkout main
301+
git switch main
303302
git pull upstream main
304303
git push origin main
305304

@@ -317,7 +316,7 @@ Another scenario:
317316

318317
Solution::
319318

320-
git checkout some-branch
319+
git switch some-branch
321320
git fetch upstream
322321
git merge upstream/main
323322
git push origin some-branch

pullrequest.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ You should have already :ref:`set up your system <setup>`,
110110
to your branch, making more changes, committing them, and pushing them to
111111
automatically update your PR::
112112

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

132-
git checkout <branch-name>
132+
git switch <branch-name>
133133
git pull upstream main # pull = fetch + merge
134134
# resolve conflicts: see "Resolving Merge Conflicts" below
135135
git push origin <branch-name>

setup.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ in the ``cpython`` directory and two remotes that refer to your own GitHub fork
9797
If you want a working copy of an already-released version of Python,
9898
i.e., a version in :ref:`maintenance mode <maintbranch>`, you can checkout
9999
a release branch. For instance, to checkout a working copy of Python 3.8,
100-
do ``git checkout 3.8``.
100+
do ``git switch 3.8``.
101101

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

0 commit comments

Comments
 (0)