git branch --List branch / Create branch

Use the "git branch" command to list branches and create branches.

List branches

To list the branches, use the "git branch" command with no arguments.

#Branch list
git branch

A list of branches is displayed. The current branch name is marked with an "*".

* blead
  fix_bug
  v2_release

Create a branch

To create a branch, specify the branch name with the "git branch" command.

#Create a branch
git branch branch name

Branch name

We recommend that you give your branch a concise name that will help you understand your development work.

An example for a development branch to add a product modification feature.

git branch goods_update

The point is that it can be distinguished from other branches and is easy to understand.

For large projects, it may be a little longer, such as with the worker's name.

What is a branch?

A branch is a feature that allows you to branch your development. For example, it is used for "adding new features", "fixing bugs", "maintenance for version 2", and so on. Think of blead here as "bread leading" in the main branch.

o --o --o --o --o --o --o blead
        | |
        | --o --o fix_bug
        |
        --o --o --o --o v2

As an internal implementation, a branch in Git is simply a reference to the beginning of a commit. Branching a commit is the creation of a branch, and the beginning of the branch where the commit branches and extends is the branch.

In Git, the branch is created as a reference, so you don't have to copy the entire branch and you can create the branch faster.

Immediately after executing "git branch", it looks like this.

Immediately after # git branch
o --o --o <-blead
           <-fix_bug

The branch is never copied, just the commit ID at the beginning of the extended o is named fix_bug. This means reference. Perl Reference and C language < If you understand the pointer of / a>, it will be relatively easy to understand.

Let's proceed with one commit in the fix_bug branch. It will be as follows.

Proceed with commit with # fix_bug

o --o --o <-blead
        |
        --o <-fix_bug

Create a branch based on other commits, branches or tags

You can also create a branch based on other commit IDs, branches, or tags. The branch can be a remote branch or a local branch. A remote branch simply means a branch in a remote repository.

git branch branch name, branch name, etc.

This is a sample to create a branch based on other commits, branches and tags.

# Based on the commit
git branch new_branch 7e4fd9251ed97e69274121a13d27f75c96ae7c61

# Based on another branch
git branch new_branch fix_bug

#Based on a remote branch
git branch new_branch origin / fix_bug

Based on the # tag
git branch new_branch v2.1

Associated Information