DEV Community

Anusha Kuppili
Anusha Kuppili

Posted on

How to Create a New Git Branch Like a Pro β€” Beginner Friendly Guide

Hey everyone! πŸ‘‹

In this post, we're going to walk through how to create a new Git branch in a project repository, step-by-step, in a way that’s perfect for beginners. Whether you're working with a team or managing your own projects, branching is a powerful way to safely develop new features without messing up your main codebase.


Why Do We Need a New Branch?

Imagine this scenario: our developers are actively working on a project inside the directory /usr/src/kodekloudrepos/official. They want to add some exciting new features, but they want to keep these changes separate from the stable master branch until everything is perfect.

Creating a new branch lets us do exactly that β€” work on new changes independently, then merge them back when they're ready.


Step-by-Step: Creating A New Git Branch

Let’s say we're on the Storage server in the Stratos DC, where the project lives.

1. Open Terminal and Navigate to the Repository

cd /usr/src/kodekloudrepos/official

Enter fullscreen mode Exit fullscreen mode

This moves us to the project folder.

2. Check Which Branch We’re On

git branch

Enter fullscreen mode Exit fullscreen mode

If we are not already on the master branch, switch to it:

git checkout master

Enter fullscreen mode Exit fullscreen mode

3. Pull the Latest Changes

It’s good practice to update our local master branch before branching off:

git pull origin master

Enter fullscreen mode Exit fullscreen mode

4. Create and Switch to a New Branch

Now, let's create a new branch called xfusioncorp_official. The command below both creates and switches us to the new branch:

git checkout -b xfusioncorp_official

Enter fullscreen mode Exit fullscreen mode

5. Push the New Branch to the Remote Repository

Finally, so everyone else can see our new branch, we push it upstream:

git push origin xfusioncorp_official

Enter fullscreen mode Exit fullscreen mode

What Just Happened?

  • We safely branched off from the main master code.
  • No changes were made yet β€” just a new "workspace" or timeline to work on.
  • This keeps the development process organized and risk-free.

Quick Tips for Beginners

  • Branch names should be descriptive; here, xfusioncorp_official relates to the project for clarity.
  • Always sync your master branch before creating branches to avoid conflicts.
  • Push your new branch so teammates can collaborate if needed.

Thanks for reading! If you’re new to Git, practicing these steps will get you confident in managing your projects with branches.

If you enjoyed this tutorial, feel free to follow for more beginner-friendly dev tips.

Happy coding! πŸš€


Top comments (0)