0Pricing
DevOps Bootcamp · Lesson

Branching & Merging Basics

Grasp the fundamentals of Git branches, how to create and switch between them, and perform simple merges.

Branching & Merging Basics is a free DevOps Bootcamp lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Intro to Git Branches

Welcome to branching! In Git, a branch is essentially an independent line of development. Think of it like taking a copy of your project at a certain point and then working on that copy without affecting the original.

Branches are crucial for:

  • Isolating features: Work on new features or bug fixes without breaking the main project.
  • Experimentation: Try out new ideas without fear of ruining your stable codebase.
  • Collaboration: Multiple developers can work on different parts of a project simultaneously.

The `main` Branch

When you initialize a new Git repository, you start with a single default branch. This is commonly named main (or sometimes master, depending on the Git version and configuration).

The main branch is usually considered the stable, production-ready version of your project. All new features or fixes are typically developed on separate branches and later merged back into main.

Creating a New Branch

To create a new branch, you use the git branch command followed by the name you want to give your new branch. This command creates a new pointer to the current commit.

For example, to start working on a 'new-feature':

git branch new-feature

Listing Your Branches

To see all the branches in your local repository, you can simply run git branch without any arguments. It will list all branches and highlight the one you are currently on with an asterisk (*).

Try running this command after creating a branch:

git branch

Switching Between Branches

Creating a branch doesn't automatically switch you to it. To move from your current branch to another, you use the git switch command.

For example, to move to the new-feature branch we just created:

git switch new-feature

Working on a Feature Branch

Once you've switched to your new branch (e.g., new-feature), any changes you make and commit will only exist on that branch. The main branch remains untouched.

This isolation allows you to develop without impacting the stable version of your project.

Let's imagine creating a file and committing it on our new-feature branch:

echo "This is a new feature!" > feature.txt
git add feature.txt
git commit -m "Add feature.txt file"

Understanding Merging

Once you've finished developing on your feature branch and are happy with the changes, you'll want to integrate them back into your main branch. This process is called merging.

Merging combines the history and changes from one branch into another, bringing your feature into the main line of development.

Performing a Simple Merge

To merge your feature branch into main, first switch back to the main branch. Then, use the git merge command followed by the name of the branch you want to merge into the current branch.

Git will try to integrate the changes. If there are no conflicts, it's usually a fast-forward merge, meaning the main branch pointer just moves forward.

git switch main
git merge new-feature

Cleaning Up Branches

After successfully merging a feature branch into main, you often no longer need the feature branch itself. It's good practice to delete merged branches to keep your repository clean and organized.

Use the git branch -d command, which safely deletes a branch only if it has been fully merged into its upstream branch (or the current branch).

git branch -d new-feature

Branching Basics Check

You've learned how to create, switch, and merge branches. Let's test your understanding.

Recap: Branches & Merges

Great job! You've grasped the fundamentals of Git branching and merging. Here's what we covered:

  • Branches provide isolated lines of development.
  • The main branch is typically your stable codebase.
  • Use git branch <name> to create a new branch.
  • Use git switch <name> to navigate between branches.
  • Use git merge <branch-to-merge> to integrate changes from one branch into your current branch.
  • Use git branch -d <name> to safely delete merged branches.

Branches are a core part of collaborative Git workflows, enabling powerful and flexible development.

Frequently asked questions

Is the “Branching & Merging Basics” lesson free?

Yes — the full text of “Branching & Merging Basics” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Branching & Merging Basics”?

Grasp the fundamentals of Git branches, how to create and switch between them, and perform simple merges. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Branching & Merging Basics” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Staging, Committing, History
  2. Undoing Changes Locally
  3. Branching & Merging Basics
  4. Stashing Work in Progress
← Back to DevOps Bootcamp