From the course: Git from Scratch
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
The difference between switch and checkout - Git Tutorial
From the course: Git from Scratch
The difference between switch and checkout
- [Instructor] Okay, there's an obvious question that needs to be answered here. Why do we have two commands, git switch and git checkout, which do pretty much the same thing? The answer is separation of concerns. The git checkout command can do several different things, and its functionality has expanded over the years. As a result, git checkout has several different meanings and uses, which can sometimes get confusing because there is no clear separation of concerns. Here's an example. In my project, I've made a change since the last commit, but I haven't staged that change yet. Then I realized I don't actually want this change. I want to restore the file to where it was when I made the last commit. As long as I haven't staged my changes, I can do this using git checkout by targeting the file in question. So if this file is called main.js, I can say, git checkout main.js. And the file is reverted to the…
Contents
-
-
-
-
(Locked)
git branch: Create an alternate timeline1m 8s
-
(Locked)
HEAD: An introduction45s
-
(Locked)
git switch: Go to an alternate timeline40s
-
(Locked)
git checkout: Go to an alternate timeline58s
-
(Locked)
DETACHED HEAD: An explanation1m 15s
-
(Locked)
The difference between switch and checkout1m 40s
-
(Locked)
-