git bash change branch code example

Example 1: how to check in which brach we are in git

git branch -a # it will show an astrick * like *master
git branch --show-current # source == git remote --help

Example 2: how to swap branch git

[git checkout "branch_name"]

is another way to say:

[git checkout -b branch_name origin/branch_name]

in case "branch_name" exists only remotely.

[git checkout -b branch_name origin/branch_name] is useful in case you have multiple remotes.

Regarding [git checkout origin 'another_branch'] I'm not sure this is possible, AFAK you can do this using "fetch" command -- [git fetch origin 'another_branch']

Example 3: git switch branch

git switch <branch_name>

git checkout <branch_name>

Example 4: how to make new branch and switch in git

git checkout -b myNewBranch

Example 5: git switch branch

git switch branch_name

git checkout branch_name

Example 6: change branch git

git checkout <branch_name>

Tags:

Misc Example