🧹 Clean Up Time: Deleting a Git Branch (Real DevOps Example)
Here’s a real-world scenario:
You’re working on a project repository located at /usr/src/kodekloudrepos/apps
. During testing, a bunch of branches were created. Now it’s time to clean up the mess.
Your task:
Delete a local Git branch named xfusioncorp_apps
.
Let’s break it down.
📁 Step 1: Navigate to the Git Repository
Move into the directory that holds your Git repository:
cd /usr/src/kodekloudrepos/apps
Make sure you’re inside a Git repo:
git status
If it shows the current branch and working directory status — you’re good.
🌿 Step 2: List the Local Branches
Let’s make sure the branch xfusioncorp_apps exists:
git branch
You’ll see something like:
* main
xfusioncorp_apps
The asterisk (*) indicates the current branch.
🚫 Step 3: Delete the Branch
You can’t delete the branch you’re currently on, so first switch to a different one — like main:
git checkout main
Now safely delete the branch:
git branch -d xfusioncorp_apps
This works only if the branch has been fully merged.
If it hasn’t, and you’re sure it’s safe to delete:
git branch -D xfusioncorp_apps
-d = delete safely if merged
-D = force delete, even if not merged
Want to Delete a Remote Branch?
You’re not doing this in the current task, but just for reference:
git push origin --delete xfusioncorp_apps
This removes the branch from the remote repository as well.
✅ Done!
That’s it. You’ve just cleaned up a Git branch the way any good DevOps engineer would. These small tasks add up to a clean, healthy, and manageable Git workflow — especially in active development environments.
🚀 Want more real-world Git and DevOps walkthroughs like this?
Follow me here on Dev.to, and subscribe to my YouTube channel:
🎥https://www.youtube.com/@DataEnthusiastEra
No fluff. No buzzwords. Just practical DevOps.