Listing, Renaming, and Deleting Branches

Git provides commands for managing branch references. Local branches can be listed with git branch, renamed with git branch -m, and deleted with git branch -d. Remote branches can be removed using git push origin --delete branch-name.

Deleting a branch does not automatically delete commits if those commits are still reachable through another reference.

Branch Maintenance
git branch
git branch -a
git branch -m old-name new-name
git branch -d feature/login
git push origin --delete feature/login
💡 These commands inspect local and remote-tracking branches, rename a local branch, delete a merged local branch, and remove a branch from the remote.
Key Takeaways
  • Use -d for safe deletion of merged branches.
  • Use -D only when intentionally forcing deletion.
  • Remote branch deletion is a push operation.
Knowledge Check

Which command safely deletes a merged local branch?