git get branch code example

Example 1: how to get current git branch

git branch --show-current

Example 2: how to see remote branch git

git remote show origin

Example 3: git branch list

git branch -a 	#all local and remote branches are listed
git branch -r 	#remote branches are listed
git branch 		#only local branches are listed

Example 4: 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 5: git checkout remote branch

git checkout --track origin/<branchname>

Example 6: get current branch name git

git rev-parse --abbrev-ref HEAD