git branch
Category: git
Date: Jan. 28, 2025, 11:29 p.m. PST
Tags: branch
Show the current branch name
git rev-parse --abbrev-ref HEAD
List remote branches
git branch -r
# or, for all branches
git branch -r -a
Move commits to a new branch
git branch <NEWBRANCH>
git reset --hard origin/<BRANCH>
git checkout <NEWBRANCH>
Creating a local branch
git checkout -b branchname
Switching between 2 branches
git checkout -
Pushing local branch to remote
git push -u origin branchname
Deleting a local branch
git branch -d branchname
Force delete a local branch
git branch -D branchname
Remove remote refs locally already removed from your remote
git remote prune origin
View all branches, including local and remote branches
git branch -a
View branches merged into current branch
git branch -a --merged
View branches not merged into current branch
git branch -a --no-merged
Viewing local branches
git branch
Viewing remote branches
git branch -r
Push local branch after rebasing master into local branch
git push origin +branchname