Managing Branches

Renaming, Deleting and Protecting Branches

git branch --merged lists branches whose tips HEAD already contains, which git branch -d deletes safely. Delete the API branches, then start the front end under a name that turns out too vague:

Deleting merged branches, and renaming oneShell
git branch --merged
git branch -d search-api sort-api
git switch -c search-box
# Edit public/index.html: build table cells with textContent
git commit -qam "Escape catalog fields instead of using innerHTML"
# Edit public/index.html: add a search form that passes ?q= to the API
git commit -qam "Add a title search box to the catalog page"
git switch -q main
git branch -d search-box
git branch -m search-box ui-search
git branch -v
Output
* main
  search-api
  sort-api
Deleted branch search-api (was c47ef58).
Deleted branch sort-api (was 8085c86).
Switched to a new branch 'search-box'
error: the branch 'search-box' is not fully merged
...
* main      1aaa0dc Merge branch 'search-api'
  ui-search 4370a11 Add a title search box to the catalog page

-d refuses an unmerged branch; -D forces it, leaving the commits only in the reflog (Recovering a Deleted Branch). git branch -m old new renames a branch with its reflog. Git 1,932 itself protects no branch: anyone who can write to a repository can move any ref. Protection lives where branches are shared: receive.denyNonFastForwards on a server repository (--force-with-lease), review rules on hosting platforms (GitHub), and hooks (Git Hooks and Automated Checks).