Skip to main content

Command Palette

Search for a command to run...

Creating a branch in Git

Updated
3 min read
Creating a branch in Git
S

Entrepreneur, Founder, Mentor. Also runs a Registered NGO. Visit my website: sandeepgokhale.com

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 // updates your remote-tracking branches, but does not merge or change local branches.

git branch -a // See the updated list of branches

git switch <base-branch-name> 
// Switch to the local base branch (e.g., develop)
// If it doesn’t exist locally yet, you’d do:
// git switch -c <base-branch-name> origin/<base-branch-name>

git pull origin <base-branch-name>
// Get latest changes from remote branch into your local base branch

git switch -c mew-branch-name
// Create a new local branch from the updated base branch

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 // get the latest code from remote. Do this always

git switch -c FEATURE_BRANCH origin/develop

// That is it. now, ill work on FEATURE_BRANCH and make the changes and push and get the PR reviewed

Pull Request

After my changes are done and the feature is working (Automated Unit & Integration Tests), I raise a PR. A Pull Request.

So, A Pull Request (PR) is a way for developers to propose changes to a codebase to ensure the code changes work correctly without causing issues. You can read more about how to create a PR effective in this blog.


Let's Connect

Hi, I’m Sandeep Gokhale, and I'm passionate about building high-performing teams at my company, Techvito and I write about Technology, People, Processes and some more fun stuff.

One of my life’s missions is to do whatever it takes to build world-class products and deliver exceptional client outcomes.

In case you're looking out for a technology partner to accelerate your business goals with clarity, speed, and quality & security, my team and I are here and more than ready to help you make it happen.

Feel free to connect with me on LinkedIn and Twitter.

Until Next time!