Git - Local branch

> Code - (Programming|Computer) Language > Code Versioning > Git

1 - 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


3 - 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.

4 - Management

4.1 - Create

  • Non-tracking local branches
git branch <branchname> [<start-point>]
git branch branchName1 branchName2
# or
# where -b create a branch and check it out with a single command
git checkout -b branchName
  • Tracking Local branch
git branch branchname <remote/branch>
git branch --track <branchname> [<start-point]
# example
git branch --track branch_name origin/branch_name

4.2 - See

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

4.3 - Delete

git branch -d <branchname>
# Force
git branch -D <branchname>

4.4 - Paths

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

code/version/git/local.txt · Last modified: 2018/07/17 12:21 by gerardnico