Branches
Notes
A branch is a reference to an existing commit (not as intuitively thought as a chain of commits).
A branch diverges from another branch only if the referenced commit shares an ancestor with another commit.
Commands
Show branches
git branch --list
, or simplygit branch
git branch -r
to list remote branchesgit show-branch -a
show a detailed listgit log --oneline --decorate --graph --all
to show a visual diagram
Create a branch
git branch <branch-name>
Change to a branch, both are equivalent. Using
switch
is more unambiguous.git checkout <branch-name>
git switch <branch-name>
Rename a branch
git branch -m <new-name>
rename current branchgit branch -m <old-name> <new-name>
other branch
Delete a local branch
git branch -d <branch-name>
if fully mergedgit branch -D <branch-name>
if not fully merged, could result in data loss. Use with caution.
Delete a remote branch
git push origin --delete <branch-name>
Last updated