About

A local branch is a branch that exists only on your computer.

A tracking branch is a local reference to a remote branch but is not a local branch

Type

There are two types of local branches:

  • non-tracking local branches. They are not associated with any other branch.
  • and tracking local branches. Tracking local branches allow you to run git pull and git push, without specifying which upstream branch to use.

Management

Create

Non-tracking local branches

git branch <branchNameToCreate> [<start-point>]
# example
git branch branchName1 branchName2

where:

  • start point may be:

Example:

  • Shortcut to create and checkout with the -b option of the checkout command
git checkout -b branchName

Local Tracking branch

git branch branchname <remote/branch>
git branch --track <branchname> [<start-point]

# example
git branch --track branch_name origin/branch_name

See

  • All
git branch
* branch_name
  master

git branch -vv
* branch_tracked 95cf879 [origin/branch_name] * Commit message
  master      f3c6174 [origin/master] * Pull Request 
  branch_not_tracked c750e03ed  * Commit message 2

Delete

git branch -d <branchname>

# Force
git branch -D <branchname>

Paths

Each local branch has a refs file under .git/refs/heads/

Rename

git branch (-m|--move) <oldbranch> <newbranch>

Example: rename master to main

git branch -m master main

List

git branch -l -vv