1. Git Branches

Branching is not the issue, the merging is… – Linus Torvalds

1.1. Branche

  1. Default branch: master

  2. Branch can have any names

  3. / in name make branch folder in .git/refs/heads/

  4. Typically use Git Flow naming convention

  5. After merging no need to delete branch

  6. Branches are only commit hashes to the most recent commit

  7. Branch weights 40 bytes + null terminator (in fact one file system sector)

  8. Can merge and rebase branches

1.2. Local storage of branches

.git/HEAD
.git/refs/heads/master
.git/refs/heads/*
.git/refs/remotes/*
.git/refs/tags/*
(HEAD detached at 44d11b0)
$ cat .git/HEAD
ref: refs/heads/master
$ cat .git/refs/heads/master
8192e9663597d1a58bb89d09b882372763395175

1.3. Working with branches

1.3.1. List branches

$ git branch
* master
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
$ git branch -avv
* master                8192e96 [origin/master] DevOps: CI/CD #time 15m
  remotes/origin/HEAD   -> origin/master
  remotes/origin/master 8192e96 DevOps: CI/CD #time 15m

1.3.2. Create branch

$ git branch [name]
$ git checkout -b [name]
$ git checkout -tb origin/master

1.3.3. Change branch

$ git checkout [name]

1.3.4. Delete branch

$ git branch -d [name]
$ git branch -D [name]