DEV Community

Cover image for Merging and Branching in DevOps.
EMMANUEL
EMMANUEL

Posted on

Merging and Branching in DevOps.

How to safely work on features using branches and how to merge them using different strategies. In this ;, i'm going to use VS Code for this project.

Step 1
We create a folder for the project.
mkdir git-merge-lab

New folder

Step 2
Moves terminal into the folder. So Git works inside the project directory only.

cd git-merge-lab

Moves into the folder

Step 3
Initialize Git: Starts Git tracking by creating. gitfolder. because Without this, Git cannot save versions of files.

git init

git init

Step 4
Creates README file with project title.A project must have files before committing.

echo "# Team Project" > README.md

Create README file

Step 5
Move file to staging area. Git only commits files that are staged.

git add README.md

git add README.md

Step 6
Saves snapshot into Git history. Allows recovery if something breaks later.

git commit -m "Initial commit"

Git Commit

Step 7
Renames default branch to main.A Modern standard branch name used by GitHub.

git branch -M main

Git main branch

FAST-FORWARD MERGE

Step 8
Creates and switches to new branch. New features should not be built on main.

git checkout -b feature-login

New feature branch

Step 9
Creates feature file. This Simulates adding new functionality.

echo "Login page created" > login.txt

Feature file

Step 10
Saves feature changes to branch.Work must be committed before merging.

git add login.txt

git commit -m "Add login feature"

Saves feature chnages to branch

Step 11
Returns to main branch.You merge into the current branch

git checkout main

Switch to main branch

Step 12
Merge Feature (Fast-Forward):Moves main forward to include feature. Because no other changes existed on main.

git merge feature-login

Merge Feature

3-WAY MERGE (PARALLEL WORK)

Step 13
Create Profile Feature : Because another feature is developed independently.

git checkout -b feature-profile
echo "Profile page created" > profile.txt
git add profile.txt
git commit -m "Add profile feature"

Profile features

Step 14
Create Settings Feature : So two branches now change project separately.

git checkout main
git checkout -b feature-settings
echo "Settings page created" > settings.txt
git add settings.txt
git commit -m "Add settings feature"

Create settings features

Step 15
Merge First Feature: It Adds profile feature to main.

git checkout main
git merge feature-profile

Merge first features

Step 16
Merge Second Feature (3-Way): It Combines two branch histories. Git must compare main, feature, and common base.
Result: Merge commit is created

git merge feature-settings

Merged second feature

MERGE CONFLICT
Step 17 : Bugfix edits same file as before.

git checkout -b bugfix-title
echo "# Team Project Version 2" > README.md
git add README.md
git commit -m "Update title in bugfix"

Merge conflict

Step 18
Feature Also Changes README

_git checkout main
git checkout -b feature-title-update
echo "# Awesome Team Project" > README.md
git add README.md
git commit -m "Update title in feature"
_

Both branches change same line

Step 19
Trigger Conflict: Git cannot auto-merge and stops.It does not know which version to keep.

git checkout main
git merge bugfix-title
git merge feature-title-update

Trigger conflict

Step 20
Fix Conflict Manually **: Open **README.md, delete conflict markers, and write:

# Awesome Team Project Version 2

Then run:

git add README.md
git commit -m "Resolve merge conflict on title"

This tells Git conflict is fixed and saves final version.

Fix conflict

SQUASH MERGE
Create Feature With Many Commits and Squash It.

git checkout -b feature-dashboard

Feature dashboard

echo "Dashboard layout" > dashboard.txt
git add dashboard.txt
git commit -m "Add dashboard layout"

create file,add and commit

echo "Add charts" >> dashboard.txt
git add dashboard.txt
git commit -m "Add charts to dashboard"

add dashboard,commit

echo "Fix alignment" >> dashboard.txt
git add dashboard.txt
git commit -m "Fix dashboard alignment"

Fix alignment,add and commit

Now squash:
It Combines many feature commits into one clean commit on main.

git checkout main
git merge --squash feature-dashboard
git commit -m "Add dashboard feature

Squash

PUSH PROJECT TO GITHUB

Step 22

Create Repository on GitHub (Website Step):

Open - https://github.com >> Log in >> Click New Repository >> Repository name: 👉 git-merge-lab. N/B❗ DO NOT check: Add README/Add .gitignore. >> Click Create Repository.

Repository name

New Repository

Why we do this: Because we need an empty online repo to receive our local project.

What you will see: A page showing commands for pushing existing repo.

Page showing commands

Step 23
Connect Local Repo to GitHub:

Copy your repo URL from GitHub, then run: Links your local project to GitHub. So Git knows where to send your code when you push.

_git remote add origin https://github.com/EMMANUELOBINNAONYEMUCHE/git-merge-lab.git
_

Connect local repo

Step 24

Push All Branches to GitHub: Uploads all branches (main, feature, bugfix) to GitHub. So Your teacher must see all merge work, not only main branch. It Links your local branches to GitHub so future pushes are easier.

git push -u origin --all

Git push all

Step 25
Confirm Upload on GitHub: Refresh GitHub page. Click Branches

You must see:

  • main
  • feature-login
  • feature-profile
  • feature-settings
  • bugfix-title
  • feature-title-update
  • feature-dashboard

Why this is important:
Confirms that your full lab work is visible for marking.

Github Confirmation

In this project, we explored safe and structured collaboration in Git using branching and merging strategies. Starting from initializing a Git repository, we created multiple feature and bugfix branches to simulate real-world DevOps workflows where developers work in parallel without breaking the main codebase.

We demonstrated:

Fast-forward merges for simple feature integration

3-way merges for parallel development scenarios

Merge conflicts and how to resolve them manually

Squash merges to maintain a clean and readable commit history

Pushing all branches to GitHub to ensure full project visibility and proper review

By using VS Code and Git commands step by step, this lab shows how developers can confidently manage features, fixes, and collaboration in a professional environment. Understanding these merge strategies is essential for working in teams, maintaining clean repositories, and avoiding production issues in DevOps and software development projects.

This workflow mirrors real industry practices and provides a solid foundation for working with Git in collaborative environments.

Top comments (0)