You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6ffd157
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: C-git-commands.asc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,7 +106,7 @@ Finally, we go through some of the details of what it actually does behind the s
106
106
==== git clone
107
107
108
108
The `git clone` command is actually something of a wrapper around several other commands.
109
-
It creates a new directory, goes into it and runs `git init` to make it an empty Git repository, adds a remote (`git remote add`) to the URL that you pass it (by default named `origin`), runs a `git fetch` from that remote repository and then checks out the latest commit into your working directory with `git checkout`.
109
+
It creates a new directory, goes into it and runs `git init` to make it an empty Git repository, adds a remote (`git remote add`) to the URL that you pass it (by default named `origin`), runs a `git fetch` from that remote repository and then checks out the latest commit into your working directory with `git switch`.
110
110
111
111
The `git clone` command is used in dozens of places throughout the book, but we'll just list a few interesting places.
Copy file name to clipboardExpand all lines: book/03-git-branching/sections/branch-management.asc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ The options described above, `--merged` and `--no-merged` will, if not given a c
67
67
You can always provide an additional argument to ask about the merge state with respect to some other branch without checking that other branch out first, as in, what is not merged into the `master` branch?
Copy file name to clipboardExpand all lines: book/03-git-branching/sections/nutshell.asc
+20-13Lines changed: 20 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,12 +91,12 @@ You can see the `master` and `testing` branches that are right there next to the
91
91
==== Switching Branches
92
92
93
93
(((branches, switching)))
94
-
To switch to an existing branch, you run the `git checkout` command.(((git commands, checkout)))
94
+
To switch to an existing branch, you run the `git switch` command.(((git commands, switch)))
95
95
Let's switch to the new `testing` branch:
96
96
97
97
[source,console]
98
98
----
99
-
$ git checkout testing
99
+
$ git switch testing
100
100
----
101
101
102
102
This moves `HEAD` to point to the `testing` branch.
@@ -116,12 +116,12 @@ $ git commit -a -m 'Make a change'
116
116
.The HEAD branch moves forward when a commit is made
117
117
image::images/advance-testing.png[The HEAD branch moves forward when a commit is made]
118
118
119
-
This is interesting, because now your `testing` branch has moved forward, but your `master` branch still points to the commit you were on when you ran `git checkout` to switch branches.
119
+
This is interesting, because now your `testing` branch has moved forward, but your `master` branch still points to the commit you were on when you ran `git switch` to switch branches.
120
120
Let's switch back to the `master` branch:
121
121
122
122
[source,console]
123
123
----
124
-
$ git checkout master
124
+
$ git switch master
125
125
----
126
126
127
127
[NOTE]
@@ -136,8 +136,8 @@ To show commit history for the desired branch you have to explicitly specify it:
136
136
To show all of the branches, add `--all` to your `git log` command.
137
137
====
138
138
139
-
.HEAD moves when you checkout
140
-
image::images/checkout-master.png[HEAD moves when you checkout]
139
+
.HEAD moves when you switch
140
+
image::images/switch-to-master.png[HEAD moves when you switch]
141
141
142
142
That command did two things.
143
143
It moved the HEAD pointer back to point to the `master` branch, and it reverted the files in your working directory back to the snapshot that `master` points to.
@@ -163,7 +163,7 @@ $ git commit -a -m 'Make other changes'
163
163
Now your project history has diverged (see <<divergent_history>>).
164
164
You created and switched to a branch, did some work on it, and then switched back to your main branch and did other work.
165
165
Both of those changes are isolated in separate branches: you can switch back and forth between the branches and merge them together when you're ready.
166
-
And you did all that with simple `branch`, `checkout`, and `commit` commands.
166
+
And you did all that with simple `branch`, `switch`, and `commit` commands.
167
167
168
168
[[divergent_history]]
169
169
.Divergent history
@@ -196,15 +196,22 @@ Let's see why you should do so.
196
196
[NOTE]
197
197
.Creating a new branch and switching to it at the same time
198
198
====
199
-
It's typical to create a new branch and want to switch to that new branch at the same time -- this can be done in one operation with `git checkout -b <newbranchname>`.
199
+
It's typical to create a new branch and want to switch to that new branch at the same time -- this can be done in one operation with `git switch -c <newbranchname>`.
200
+
201
+
The `-c` flag stands for create, you can also use the full flag: `--create`.
202
+
====
203
+
204
+
[TIP]
205
+
====
206
+
To return to your previously checked out branch, also `git switch -` works, so you don't have to type that branche's name.
200
207
====
201
208
202
209
[NOTE]
203
210
====
204
-
From Git version 2.23 onwards you can use `git switch` instead of `git checkout` to:
211
+
In Git versions before 2.23, `git switch` wasn't yet available.
212
+
`git checkout` can be used instead:
205
213
206
-
- Switch to an existing branch: `git switch testing-branch`.
207
-
- Create a new branch and switch to it: `git switch -c new-branch`.
208
-
The `-c` flag stands for create, you can also use the full flag: `--create`.
209
-
- Return to your previously checked out branch: `git switch -`.
214
+
- Switch to an existing branch: `git checkout testing-branch --`.
215
+
- Create a new branch and switch to it: `git checkout -b new-branch`.
216
+
The `-b` flag stands for "`[create a new] **b**ranch`", but doesn't have a long-option equivalent.
Copy file name to clipboardExpand all lines: book/05-distributed-git/sections/maintaining.asc
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,11 +19,11 @@ As you'll remember, you can create the branch based off your `master` branch lik
19
19
$ git branch sc/ruby_client master
20
20
----
21
21
22
-
Or, if you want to also switch to it immediately, you can use the `checkout -b` option:
22
+
Or, if you want to also switch to it immediately, you can use the `switch -c` option:
23
23
24
24
[source,console]
25
25
----
26
-
$ git checkout -b sc/ruby_client master
26
+
$ git switch -c sc/ruby_client master
27
27
----
28
28
29
29
Now you're ready to add the contributed work that you received into this topic branch and determine if you want to merge it into your longer-term branches.
@@ -193,7 +193,7 @@ For instance, if Jessica sends you an email saying that she has a great new feat
If she emails you again later with another branch containing another great feature, you could directly `fetch` and `checkout` because you already have the remote setup.
@@ -499,7 +499,7 @@ In fact, if you build Git from source code cloned from the Git repository, `git
499
499
If you're describing a commit that you have directly tagged, it gives you simply the tag name.
500
500
501
501
By default, the `git describe` command requires annotated tags (tags created with the `-a` or `-s` flag); if you want to take advantage of lightweight (non-annotated) tags as well, add the `--tags` option to the command.
502
-
You can also use this string as the target of a `git checkout` or `git show` command, although it relies on the abbreviated SHA-1 value at the end, so it may not be valid forever.
502
+
You can also use this string as the target of a `git switch` or `git show` command, although it relies on the abbreviated SHA-1 value at the end, so it may not be valid forever.
503
503
For instance, the Linux kernel recently jumped from 8 to 10 characters to ensure SHA-1 object uniqueness, so older `git describe` output names were invalidated.
0 commit comments