Git - Local branch

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





Discover More
Git - Detached HEAD

What means a DETACHED HEAD in git
Git - Fetch (Remote Repository Sync)

A fetch will sync information locally from a remote repository. It will mostly git fetch: download new remote branch download all commits added since the last fetch to the actual branch ( The head...
Git - Merge

Merge is a git merge tool that is designed to integrate changes from one branch into another branch It joins two or more branch together (ie development histories) The pull command is a wrapper that...
Commit History Master
Git - Remote-tracking branch

Remote-tracking branches are local references to the state of remote branches You can't modify them. They’re just local references that you can’t move. They represent the state of the remote repository...
Git - Tracking Branch

Tracking branches are local branches that have set their upstream branch. tracking branchreference The local branches have then a direct relationship with their upstream branch that can be: a remote...
Git - Upstream Branch (Tracking branch)

An upstream is a configuration of a local branch that set the remote branch that it's tracking. cloning @{u} or @{upstream} means the upstream branch of the current branch @{upstream} or @{u}...
Branches Git
Git - Branch

This page talks Branch management in Git. For Git, a branch is: a commit name (ref) that points to the last commit (head) leaf in the commit log (or log) that represents a commit chain Example...



Share this page:
Follow us:
Task Runner