how to switch branches in git bash
Use:
bash
git switch branch-name
That’s the simplest way to change branches in Git Bash. This command switches
you to an existing branch, and the older alternative is git checkout branch- name.
Common cases
-
Switch to an existing branch:
bash git switch feature-branch -
Create and switch to a new branch:
bash git switch -c new-branch -
Go back to the previous branch:
bash git switch -
If the branch is remote
If the branch exists on the remote but not locally yet, run:
bash
git fetch
git switch branch-name
Git can then create a local tracking branch in many cases.
Example
If your branch is called login-page, you would type:
bash
git switch login-page
Note
git switch is the cleaner modern command for branch changes, while git checkout is the older, more overloaded command that also handles files and
commits.