| | 192 | To make a new branch equivalent to the current branch: |
| | 193 | {{{ |
| | 194 | git checkout -b <new_branch_name> |
| | 195 | }}} |
| | 196 | |
| | 197 | To switch from one branch to another, just check out the other branch: |
| | 198 | ((( |
| | 199 | git checkout <other_branch> |
| | 200 | }}} |
| | 201 | |
| | 202 | Note git will not let you switch to a different branch if you have uncommitted changes in tracked files. |
| | 203 | To get around this, the simplest thing to do is to commit your modified files in a temporary commit, |
| | 204 | then undo that commit later. You can also "stash" your work, which actually makes a commit on a special |
| | 205 | branch. Since it's easy to forget what's in the stash, unless you're only stashing briefly, a real commit |
| | 206 | with an informative message is probably better. |
| | 207 | |
| | 208 | To list all the branches in the repository: |
| | 209 | {{{ |
| | 210 | git branch -v |
| | 211 | }}} |
| | 212 | The -v (for verbose) tells git to show not just the branch names, but also the head commit's revision number and message. |
| | 213 | |
| | 214 | To rename the current branch: |
| | 215 | {{{ |
| | 216 | git branch -m <new_branch_name> |
| | 217 | }}} |
| | 218 | |
| | 219 | To rename a branch that is not checked out: |
| | 220 | {{{ |
| | 221 | git branch -m <old_branch_name> <new_branch_name> |
| | 222 | }}} |
| | 223 | |
| | 224 | To delete a branch: |
| | 225 | {{{ |
| | 226 | git branch -d <branch_to_delete> |
| | 227 | }}} |
| | 228 | |
| | 229 | Under some circumstances, git will complain when you try to rename or delete a branch. If you are sure |
| | 230 | you want to do it, use -M instead of -m for rename, or -D instead of -d for delete. |