Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Git Bonsai, or Keeping Your Branches Well Pruned

March 26, 2014
Steve Milner Sam Van Oort
Related topics:
DevOps
Related products:
Red Hat OpenShift

    Today, we’ll share a small victory in our DevOps journey at Red Hat IT. This cross-team collaboration has saved our IT organization some headaches and wasted time. We open-sourced the code, hoping it can help you, too.

    The Dev problem, from Sam Van Oort:

    Old, pruned git branches are sometimes re-created by accident, making a mess for our developers.

     

    Code repositories are the final resting place for code, acting as equal parts bank vault, museum, and graveyard. Unlike a vault, content is almost always added faster than it is removed, but much like a graveyard, there is a definite miasma when a repository becomes too full. That smell is developer frustration, as they have to search through dozens, or eventually, hundreds of branches to find the one they want.

    We've had sporadic cases where branches did not get merged into masters (and sometimes fixes were overwritten in later releases) and have wasted collectively hundreds of developer hours on "which branch is this in?" exchanges.

    This situation becomes worse when dealing with a configuration management system like Chef or Puppet. In Red Hat IT, Puppet environments are also defined by branch names, and there's a hierarchy in which branch they look to for code. We had a case where a branch used in testing new code was re-pushed by accident, breaking the ability to create new nodes in that dev environment, and greatly puzzling two developers.

    The solution is to periodically prune branches and throw out content which is no longer needed. But, there’s a big problem: git provides one very dangerous command that can quickly undo all your careful pruning work: "git push." One developer that accidentally runs this (rather than “git push origin branchname”) can immediately recreate all the branches that were so carefully removed.

    The Ops collaboration, from Steve Milner:

    Hey, we have pre-receive hooks in git. We can solve this, and prevent yet another “did I do that?!” moment.

    To address this challenge, the Inception team put together a free, open source git branch blacklisting tool that adds shell commands to “blacklist” branches, and has git hooks to prevent accidental re-pushes.

    Two approaches originally came to mind while thinking about implementation of a blacklisting tool: an in-repo blacklist file and a server-side configuration blacklist. After mulling over the two approaches we decided that having an in-repo blacklist file may lead to developers accidentally merging or overwriting each others’ blacklisted branches and that would negate the tool’s purpose! Instead, the idea of using the built in git config system to house a master list of blacklisted branches on the git origin was chosen. Since all of our git repositories utilize ssh as the transport it became trivial to use ssh to execute git config on the server side allowing for adding, listing, and removing of blacklisted branches. The server side would also house a pre-receive hook which checks the blacklist before allowing the branch to be pushed.

    It was important to make the tool as easy as possible so developers could use it without remembering special conventions. Forcing developers to remember the right remote commands to modify the blacklist was out of the question. The tool also needed to work in a similar fashion as other git tools. To that end, the client side of the tool, wrapping remote execution, was named git-branch-blacklist. By using this name the developer can call it directly or as git branch-blacklist. The tool also follows a simple convention of git branch-blacklist $COMMAND where $COMMAND is add, remove, or list.

    Finally, adding the pre-receive hook needed to be as easy as possible. So, we wrote a hook installer named git-branch-blacklist-install. It simply verifies the repository is set up in such a way the blacklist system will work, and then copies the hook into the right location for said repository.

    The implementation was not without its downsides. It assumes ssh is your transport, so if you use a different transport and disable ssh access, it doesn’t work. Also, the tool is written in shell script and requires common unix tools. If someone wanted to run this tool on Windows they would need to install Cygwin first. That said, the downsides were acceptable as they don’t apply to our use cases.

    The DevOps success:

    Today, Sam’s team has implemented the git-branch-blacklist tool. They’re at 180 and 65 branches (after initial pruning) in their two main repositories, and expect blacklisting to help reduce this over time, saving much developer time and frustration. Nobody has fessed up to git-branch-blacklist saving their hide just yet, but we suspect it’s just a matter of time.

    Last updated: January 10, 2023

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.