Git - Branch

1 - About

Branch management in Git.

A branch is a refs.

         CA1--CA2--CA3 <-- Branch A
        /
 C1--C2--C3 <-- master
        \
         CB1--CB2 <-- Branch B

The term "branch head" (or just "head") reference to the most recent commit on a branch. In the example above, the branch head of:

  • the branch A is the commit CA3
  • the branch B is the commit CB2

The git branch list, create, or delete branches.

3 - name

[remote/]name

when a name is fully qualified, it's a remote-tracking branch

4 - Usage

Creating two features:

  • heart glasses
  • cowboy hat

Each feature is added back to the master individually. So if glasses are finished before the cowboy hat, no problem.

Create a branch off of develop called “feature-[feature name]”, work and commit into that branch.

5 - Example of lifecycle

Example of workflow

# Create a feature branch
git checkout -b feature-myfeature develop
# Merge your work
git checkout develop
git merge --no-ff feature-myfeature
# Delete your branch
git branch -d feature-myfeature
# Integrate your work into the master repo
git push origin develop

6 - Type

7 - Management

7.1 - Working

The starred branch is the working branch

git branch
* branch-2.3
  master

or

git rev-parse --abbrev-ref HEAD
branch-2.3

7.2 - Create

  • Create one or several branches
git branch branchName1 branchName2
# or
git checkout -b branchName

7.3 - Fetch

fetch all the remote branches from origin

git fetch origin

7.4 - List

7.4.1 - All

git branch -v -a
* master

7.4.2 - Remote-tracking

See list

7.5 - Checkout

Check out an existing branch

7.5.1 - From the actual commit

cd path/to/repository
git checkout brancheName
# Example
git checkout 1.01_hello_world 

where:

7.5.2 - From a tag

See checkout

7.6 - Stash

stash In case of modification, revert to the HEAD branches

git stash # keep the modification in a stash branch
git pull # get the last one
git stash pop # Destash the modification

7.7 - Switch

See Git - Checkout

git checkout branchName
Switched to branch 'branchName'

7.8 - Share

When you want to share a branch with the world, you need to push it up to a remote that you have write access to.

git push <remote> <branch>

8 - Documentation / Reference

code/version/git/branch.txt · Last modified: 2018/06/11 14:53 by gerardnico