Skip to content

Commit 02d1043

Browse files
committed
Update to use git switch instead of git checkout
The new commands `git switch`and `git restore` were introduced in 2.23 back in August 2019, and are much cleaner than the old `git checkout`, so I believe that we should be teaching the new way, not the old. While `git switch` and `git restore` are in principal still marked as experimental in the documentation, they are here to stay. Even output from commands like git status, have gone away from suggesting `git checkout`. This commit goes through all the README files and makes appropriate changes to recomend `git switch` instead of `git checkout` (and `git switch -c` instead of `git checkout -b`) The actual setup scripts are still left untouched for maximum compatablility. If you have e.g. participants in a training using very old Git versions, it is still a lot easier to tell them to use `git checkout` when `git switch`is mentioned, than it is to debug scripts that are failing miserably.
1 parent 8939fd0 commit 02d1043

File tree

9 files changed

+16
-19
lines changed

9 files changed

+16
-19
lines changed

3-way-merge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ You again live in your own branch, this time we will be doing a bit of juggling
2525
- `git branch`
2626
- `git branch <branch-name>`
2727
- `git branch -d <branch-name>`
28-
- `git checkout <branch-name>`
29-
- `git checkout -b <branch-name>`
28+
- `git switch <branch-name>`
29+
- `git switch -c <branch-name>`
3030
- `git branch -v`
3131
- `git add`
3232
- `git commit`

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ git stash apply <stash> # Apply given <stash>, or if none given
131131

132132
# Working with Branches
133133
git branch my-branch # Create a new branch called my-branch
134-
git checkout my-branch # Checkout ("Switch" to work on) my-branch
135-
git checkout -b my-branch # Create a new branch called my-branch AND switch to it
134+
git switch my-branch # Switch to a different branch to work on it
135+
git switch -c my-branch # Create a new branch called my-branch AND switch to it
136136
git branch -d my-branch # Delete branch my-branch that has been merged with master
137137
git branch -D my-branch # Forcefully delete a branch my-branch that hasn't been merged to master
138138

@@ -155,10 +155,10 @@ git mv <source/file> <destination/file> # move/rename file and stage the chang
155155
# Aliases - it's possible to make aliases of frequently used commands
156156
# This is often done to make a command shorter, or to add default flags
157157

158-
# Adding a shorthand "co" for "checkout"
159-
git config --global alias.co "checkout"
158+
# Adding a shorthand "sw" for "switch"
159+
git config --global alias.sw "switch"
160160
# Usage:
161-
git co # Does a "git checkout"
161+
git sw master # Does a "git switch master"
162162

163163
## Logging
164164
git log --graph --oneline --all # Show a nice graph of the previous commits

basic-branching/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
## The task
88

99
You again live in your own branch, this time we will be doing a bit of juggling with branches, to show how lightweight branches are in git.
10-
Hint: `git switch` and `git checkout` will make you switch from one branch to another.
10+
Hint: `git switch` will make you switch from one branch to another.
1111

1212
1. Use `git branch` to see the two branches that are relevant for this exercise
1313
2. What branch are you on?
@@ -31,8 +31,7 @@ Hint: `git switch` and `git checkout` will make you switch from one branch to an
3131
## Useful commands
3232

3333
- `git switch`
34-
- `git checkout`
35-
- `git checkout -b`
34+
- `git switch -c`
3635
- `git log --oneline --graph`
3736
- `git branch`
3837
- `git diff`

basic-staging/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ You live in your own repository. There is a file called `file.txt`.
5050
- `git commit`
5151
- `git commit -m "My lazy short commit message"`
5252
- `git reset`
53-
- `git checkout`
5453
- `git log`
5554
- `git log -n 5`
5655
- `git log --oneline`

commit-on-wrong-branch/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Note: since the `B` in the current and in the target structure don't have the sa
5858
## Useful commands
5959

6060
- `git log --oneline --graph --all`
61-
- `git checkout <branch-name>`
61+
- `git switch <branch-name>`
6262
- `git rebase <branch-name>`
6363
- `git branch <branch-name>`
6464
- `git reset --soft HEAD~`

detached-head/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ We want to have a branch called `the-beginning` that is made from the first comm
2121

2222
- `git status`
2323
- `git log --oneline --graph --all`
24-
- `git checkout <ref>`
25-
24+
- `git checkout <ref>` or `git switch --detach <ref>`

ff-merge/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
You again live in your own branch, this time we will be doing a bit of juggling with branches, to show how lightweight branches are in git.
1010

1111
1. Create a (feature)branch called feature/uppercase
12-
2. Checkout the branch
12+
2. Switch to this branch
1313
3. What is the output of `git status`?
1414
4. Edit the greeting.txt to contain an uppercase greeting
1515
5. Add greeting.txt files to staging area and commit
@@ -18,7 +18,7 @@ You again live in your own branch, this time we will be doing a bit of juggling
1818

1919
*Remember: you want to pull in the commit on the feature branch into master. The command 'git merge [branch name]' takes one branch as argument from which it takes commits. The commits are applied to the branch pointed to by HEAD (currently checked out branch).*
2020

21-
8. Checkout `master` branch
21+
8. Switch to the `master` branch
2222
9. Use `cat` to see the contents of the greetings
2323
10. Diff the branches
2424
11. Merge the branches
@@ -30,7 +30,7 @@ You again live in your own branch, this time we will be doing a bit of juggling
3030
- `git branch`
3131
- `git branch <branch-name>`
3232
- `git branch -d <branch-name>`
33-
- `git checkout`
33+
- `git switch`
3434
- `git branch -v`
3535
- `git add`
3636
- `git commit`

rebase-branch/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You again live in your own branch, this time we will be doing a bit of juggling
1414
4. How does the log compare to the log on the master branch?
1515
5. Rebase your uppercase branch with the master (`git rebase master`)
1616
6. What did just happen? Draw it!
17-
7. Now checkout the master branch
17+
7. Now switch to the master branch
1818
8. Merge uppercase into master
1919
9. What does the log look like now?
2020

reverted-merge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ features should be included in `mymodule.txt`.
4949
* `git log --oneline --graph --all`
5050
* `git add <file-name>`
5151
* `git revert --continue`
52-
* `git checkout <branch-name>`
52+
* `git switch <branch-name>`
5353
* `git merge <branch-name>`
5454
* `git reset --hard <sha1>`
5555
* `git revert <sha1>`

0 commit comments

Comments
 (0)