Creating a branch in Git

The fear of git

Often times, Students/job seekers find git a overwhelming. I'm not sure if its the command line, all existing tutorials are complicated or not able to try and learn.

The importance of Git

Git is a fundamental tool which every aspiring engineer need to know and use daily. It is a widely used distributed version control system. Its open source and free. Git is designed to handle everything from small to very large projects with speed and efficiency.

Having basic knowledge of git is vital for freshers. Once you understand the basics, it becomes an incredibly powerful tool in your toolkit and its a skill you will use daily for a good foreseeable future.

Why should freshers/job seekers learn git ?

Once you join a company, most likely you will not be working alone in the code, There will be existing team members and also new joiners who would also work on the code. As a fresher, you will have collaborate with other developers and ensure everything goes smooth.

What could go wrong if you don't know git well?

Incorrect use of git could lead to:

  1. Rework.

  2. Overwriting changes of others.

  3. Slowness of delivery.

  4. Unhappy teammates/clients

  5. Loss to business.

Enough said, let's move on.

Key features of Git

Below are some major features of git compared to other version control systems.

  1. Its Distributed

  2. Supports Branching & Merging

  3. Data Assurance

  4. Of course, Version Control

  5. Has a staging Area and many more.

Branching

One of the features of git is branching. A branch is nothing but a light weight movable pointer which points to a "snapshot" of code. From this branch, we can create another branch by giving it a name.

Some important commands

git branch -a // List of branches.

git fetch origin // List of branches at origin, Origin is remote repository.

git checkout -b <your-branch-name> origin/<base-branch-name> 
// This will create a new branch from base-branch-name. 
// Any changes you make will not impact base-branch-name.

git pull origin <branch-name>
// This will get you latest code from remote repository ( or clould)

Here is how I create a branch

Consider a scenario where I have to create a feature branch (A branch where a new feature would go) from develop (base branch) branch. Here is how I do it

git status // Just to make sure I do not have any changes 

git checkout develop // Since I've already pulled it once

git pull origin develop 

git checkout -b FEATURE_BRANCH origin/develop  

// That is it. now, ill work on FEATURE_BRANCH and make the changes I have to

More to come.

Did you find this article valuable?

Support Sandeep Gokhale's Blog by becoming a sponsor. Any amount is appreciated!