As a general rule, your working copy does NOT have to be clean before you can use 'switch'. Switch to the specified branch and discard any local changes to obtain a clean working copy. You can also specify a starting point (either another branch or a concrete revision) if you don't provide any specific starting point, the new branch will be based on the current HEAD branch.
Using the '-c' flag, you can specify a name for a new branch that should be created. The name of a new local branch you want to create. If you specify the name of an existing local branch, you will switch to this branch and make it the current 'HEAD' branch.īut you can also specify a remote branch: in that case, Git will create a new local branch based on that remote branch and set up a tracking relationship. The name of a local or remote branch that you want to switch to. It has a very clear and limited purpose: switching and creating branches! Important Options
The 'switch' command provides a simple alternative to 'checkout'. The problem with 'checkout', however, is that it's a very versatile command: you can not only use it to switch branches, but also to discard changes, restore files, and much more. It's relatively new (added in Git v2.23) and provides a simpler alternative to the classic 'checkout' command.īefore 'switch' was available, changing branches had to be done with the 'checkout' command. The 'switch' command allows you to switch your current HEAD branch.