Switching or changing branches is the most common git command which we developers use a lot. You may be still using
git checkout command for this. But are you aware of the
git switch command which is more easier to change branches in git?
Git 2.23 came up with the new ‘ git switch ’ command, which is not a new feature but an additional command to ‘switch/change branch’ feature which is already available in the overloaded git checkout command.
Currently, the all-encompassing command – git checkout does many things. It can be used to switch branches and also to restore the working tree files.
To separate out the functionalities, the GIT community introduced the new git switch branch command which is an attempt to start to scale back to the responsibilities without breaking backward compatibility.
git switch <branch-name>
The new ‘experimental’ git switch branch command is meant to provide a better interface by having a clear separation, which helps to alleviate the developers’ confusion when using git checkout.
One such example is git checkout which reverses the modifications of an unstaged file and git checkout which switches branch.The dilemma is more when the filename and branchname are the same.
The new commands, git restore (takes care of operations that change file), and the git switch (takes care of operations that change branches) shares out the responsibilities of git checkout in a more intuitive way.
To read our indepth tutorial with more detailed examples on how to use
git switch command, please visit -https://bluecast.tech/blog/git-switch-branch/
Also, dont forget to check my previous tutorial on git stash