Branching in Git

Branching in Git

 Branching in Git


The Git branches are simply pointers to a specific commit. There is no storage/memory overhead with making multiple branches in your git repository. It is easier to logically divide up your work into smaller branches than heavy branches. For example, you want to add a new feature or fix a bug the branches are the best use for the tasks.

Create New Branch

This will create a new branch named “develop”. Your existing branch is still your current branch.

git branch develop

Switching Branches

Use the git checkout command to switch to other branches. The below command will switch you to a branch named “develop”.

git checkout develop

Create and Switch Branch

Instead of using separate commands to create branches and switch. You can do the same with a single command. This will create a new branch and switch immediately.

git checkout -b develop

List Branches

Use git branch command to list currently available branches. The * shows the active branch

git branch

* develop
  master

Fetch Remote Branches

Another developer has created a new branch and pushed it to the remote git repository. Now you need to fetch that branch in your development environment. You can fetch all branches available on a remote git repository using the command:

git fetch --all

After that switch to that branch using git checkout.

git checkout other_branch
Reactions

Post a Comment

0 Comments

close