Git Branches

Working with Git branches

Create Branch

git branch branch-name # create new branch
git checkout -b branch-name # create and switch
git switch -c branch-name # create and switch (newer)

Switch Branch

git checkout branch-name # switch to branch
git switch branch-name # switch to branch (newer)
git checkout - # switch to previous branch

List Branches

git branch # list local branches
git branch -a # list all branches
git branch -r # list remote branches

Delete Branch

git branch -d branch-name # delete merged branch
git branch -D branch-name # force delete branch
git push origin --delete branch-name # delete remote branch

Rename Branch

git branch -m new-name # rename current branch
git branch -m old-name new-name # rename specific branch