Branching
suggest changeSyntax
git branch [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]git branch --unset-upstream [<branchname>]git branch (-m | -M) [<oldbranch>] <newbranch>git branch (-d | -D) [-r] <branchname>…git branch --edit-description [<branchname>]git branch [--color[=<when>] | --no-color] [-r | -a] [--list] [-v [--abbrev=<length> | --no-abbrev]] [--column[=<options>] | --no-column] [(--merged | --no-merged | --contains) [<commit>]] [--sort=<key>] [--points-at <object>] [<pattern>…]
| Parameter | Details |
|---|---|
| -d, --delete | Delete a branch. The branch must be fully merged in its upstream branch, or in HEAD if no upstream was set with --track or --set-upstream |
| -D | Shortcut for --delete --force |
| -m, --move | Move/rename a branch and the corresponding reflog |
| -M | Shortcut for --move --force |
| -r, --remotes | List or delete (if used with -d) the remote-tracking branches |
| -a, --all | List both remote-tracking branches and local branches |
| –list | Activate the list mode. git branch <pattern> would try to create a branch, use git branch --list <pattern> to list matching branches |
| –set-upstream | If specified branch does not exist yet or if --force has been given, acts exactly like --track. Otherwise sets up configuration like --track would when creating the branch, except that where branch points to is not changed |
Every Git repository has one or more branches. A branch is a named reference to the tip commit of a line of history.
A repository has a current branch (marked with * in the list from git branch). Whenever you create a commit with git commit, that commit becomes the tip of the current branch, and the previous tip becomes its parent.
A new branch points at the same commit as the branch it was created from until something is committed on the new branch.
Creating and checking out new branches
Quick switch to the previous branch
Check out a new branch tracking a remote branch
Create an orphan branch i.e. branch with no parent commit
Move current branch HEAD to an arbitrary commit
Overwrite single file in current working directory with the same from another branch