git branch
git
Usage
git branch [-a|-vv] [-d <name>]Lists, creates and deletes branches locally; deleting one leaves the remote copy alone, so the server still needs git push origin --delete.
Common flags
| Flag | Meaning |
|---|---|
| -a | local and remote-tracking branches |
| -r | remote-tracking branches only |
| -vv | last commit and upstream of each branch |
| -d <name> | delete a branch that is already merged |
| -D <name> | delete it even if unmerged; those commits are left behind |
| -m <old> <new> | rename |
| --merged | branches already contained in the current one |
| --show-current | print the branch you are on |
Examples
git branch -vvevery local branch with its upstream and last commit
git branch -d old-featureremoves a merged branch locally only
git push origin --delete old-featurethe separate step that removes it on the server
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git branch do?
Lists, creates and deletes branches locally; deleting one leaves the remote copy alone, so the server still needs git push origin --delete.
Q. How do I type it?
git branch [-a|-vv] [-d <name>] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
8 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-branch