how to checkout a branch in git 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: git checkout new branch

// create and checkout new branch in one line
git checkout -b new_branch

Example 3: canging branch in git

$ git checkout <existing_branch>

$ git checkout -b <new_branch>

Example 4: git branch and checkout at the same time

$ git checkout -b <branch_name>

Example 5: git checkout to remote branch

$ git checkout --track origin/newsletter
Branch newsletter set up to track remote branch newsletter from origin.
Switched to a new branch 'newsletter'

Example 6: git checkout commit

git checkout <commit>

Tags:

Php Example