Introduction to Git Branch

Branching means diverging from the mainline and continue to work separately without messing with the mainline. Nearly every VCS has some form of branch support. In Git, a branch is simply a reference to the commit, where the following commits will be attached.

Git vs SVN: In recent years, the use of git has risen tremendously. Unlike SVN, git allows users to work on their own copy of the repository. One of the main reason for git’s success is its speed. Since all the files are stored locally on the developer’s computer, he/she has access to all even in very poor internet connection. Branching in other VCS can be an expensive operation in both time and disk space.

Git vs Other VCS: Git branching feature is what that sets it apart from other VCS tools. Git branch operation is nearly instantaneous, making the flow of switching back to branches and forth very smooth. Following are the few pros why git is preferred over other VCS:

  • High operation Speed
  • Full history of tree available
  • Branch Operations
  • Sorted Distributed Model

Branches: When you make a commit, Git stores a commit object that contains a pointer to the snapshot of the content you staged. This object also contains the author’s name and email address, the message that you typed, zero parents for the initial commit, one parent for a normal commit, and multiple parents for a commit that results from a merger of two or more branches. A branch as discussed earlier is a separate line of development as git stores branch as a reference to commits.

Note: Git branch is used to list, create or delete branches and it’s easier to logically divide up your work than have big beefy branches.

Git Branch- options

Options Description
git -a This options list both remote-tracking branches and local branches.
git branch – – list Activate the list mode or simply git branch list all the branches of repository.
git -c “Branch” This option is used to Copy a branch.
git -C “Branch” It is a shortcut for – – copy – – force
git -d or – – delete “Branch” This option deletes specified branch. The branch must be fully merged in its upstream branch.
git -D “Branch” This is a shortcut for – – delete – – force. It deletes the branch even if it has unmerged changes.
git -m “Branch” This option move/rename the branch.
git -M “Branch” It is a shortcut for – – move – – force.
git -q or – – quiet when creating or deleting a branch, this option suppresses non-error messages.
git -r or – – remote This option is used to list all the remote-tracking branches. If used with -d, this can also be used to delete remote branches.
git -t or – – track When you create a new Branch it set up configuration to mark the start-point branch.
git – -no-track It does not set ip the “upstream” configuration.
git – -edit-description It edits the description of what the branch is for.
git – – – -contains [] Show the list of branches that contain specified commit.