Skip to content
Related Articles

Related Articles

Improve Article

Introduction to Git Branch

  • Last Updated : 22 Aug, 2019

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

OptionsDescription
git -aThis options list both remote-tracking branches and local branches.
git branch – – listActivate 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 – – quietwhen creating or deleting a branch, this option suppresses non-error messages.
git -r or – – remoteThis 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 – – trackWhen you create a new Branch it set up configuration to mark the start-point branch.
git – -no-trackIt does not set ip the “upstream” configuration.
git – -edit-descriptionIt edits the description of what the branch is for.
git – – – -contains []Show the list of branches that contain specified commit.

    Following are the series of snapshots of executions of above few commands.

    • Git branch listing the one and only branch of the project ie. Master Branch

    • Renaming Master Branch

    • Copying “Branch2” and creating “branch3”

    • Deleting “branch3”

    Summarizing: In this article, we discussed the high operation speed and branch behavior. We learned about the git branch command whose primary function is to list, create, delete branches. We also learned about various git branch option to fully implement the functionality of this command.

    Go Premium (An Ad Free Experience with many more features)

    My Personal Notes arrow_drop_up
Recommended Articles
Page :