What IS git switch!?
`git switch` separates branch switching from `git checkout`, while `git restore` handles restoring paths from an index or tree.
Transcript 1 topic
Git switch vs checkout
0:00What is the git switch command, and why should you care? And should you even use it? It's not surprising that most people don't know about git switch. I mean, it is four years old. What does it do?
Let's start with the command we do know, git checkout. Git checkout actually performs two different things. One, checking out a branch to advance its history or checking out a path of an index or tree ish to advance the current history. But these are being split into two different commands, git switch and git restore. Git switch focuses on checking out a branch to advance its history.
Git restore will focus on checking out paths of an index or tree ish to advance the current history. So have you ever been working and then realized too late that you've been working in the main or master branch this whole time? Me too. And that is the perfect use case for git switch. Of course, you can still use git checkout dash b in the branch name, but it's just as easy to do git switch dash c in the branch name.
Do you have a git command that you don't understand or would like to know more about? Well, leave a note in the comments and I'll do a quick explainer to let you know how it works.
Sign in to join in. Reading needs nothing.