# Creating & Switching Branches — Git

Source: https://www.geekswithgeeks.com/en/git/git-branch-commands

> git branch and git switch/checkout in practice.

## List, create, switch

`git switch -c` creates and moves to a new branch in one step — the modern replacement for `checkout -b`.

```bash
git branch                 # list branches
git switch -c feature/login
# equivalent older form:
git checkout -b feature/login
```

Output:

```
Switched to a new branch 'feature/login'
```

## Rename & delete

`-d` deletes a merged branch safely; `-D` force-deletes even if it has unmerged work.

```bash
git branch -m old-name new-name
git branch -d feature/login    # safe delete
git branch -D feature/login    # force delete
```

## switch vs checkout

`git checkout` does too many things (branches *and* files). `git switch` and `git restore` split those jobs apart and are easier to reason about.
