Can GitHub Flow be used for deploying to Development, Staging, and Production? #196024
-
🏷️ Discussion TypeQuestion 💬 Feature/Topic AreaWorkflow Deployment Discussion DetailsI've known about GitFlow and GitHub Flow for about two years now. But as time goes by, I understand both of them better than I did when I first learned about them. Git Flow strikes me as an approach that would work well, if your company's approach is to always maintain a Development, Staging, and Production branches. When I work, we've been using GitHub Enterprise in our GitHub Organizations for 3 years, but we really haven't done this rigorously. Another thing which has been in place here for many years is having a Development, Test (or Staging), and Production environment. These haven't been enforced using repos with appropriately named branches. It's just been an approach which has been followed long enough that it's been in place before I was hired. Then there is GitHub Flow, which is simpler and cleaner. Personally, I prefer this approach. I like the idea of having just one, long-lived branch, the default branch. Then as many feature branches as you need, but they all should (ideally) go away once they've been merged back in main. And I've been championing this approach for a long time, but it really hasn't been adopted where I work. I don't think people have understood GitHub Flow. Perhaps I haven't done a good enough job explaining it. But now I'm wondering if a big part of it is because the cultural mindset is we must always have a development, staging, and production environment. And without realizing it until now, the GitFlow approach seems better suited to the cultural approach followed here since time began (at least here). But, as one last ditch effort to try and get GitHub Flow adopted, I'm wondering if a GitHub Flow branching and project management approach could still be used to deploy to Development, Staging, and Production environments? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 19 replies
This comment was marked as low quality.
This comment was marked as low quality.
-
|
Hey @Rod-at-DOH Dev environment => triggered when a PR is opened from any feature branch So main stays clean and is always your single source of truth. No painful merge conflicts between long-lived branches, no GitFlow tax. |
Beta Was this translation helpful? Give feedback.
-
|
Short answer: yes, and that's actually how most teams running GitHub Flow at scale do it. The trick is decoupling branching strategy from deployment strategy — those are two separate things and Git Flow conflates them. In GitHub Flow you have one long-lived branch ( A common mapping that works well:
Why this is better than Git Flow's
The piece your colleagues are probably missing: Environments Repo → Settings → Environments → create Then in the workflow: jobs:
deploy-dev:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment: development
runs-on: ubuntu-latest
steps: [...]
deploy-staging:
if: github.event_name == 'release'
environment: staging
runs-on: ubuntu-latest
steps: [...]
deploy-prod:
needs: deploy-staging
environment: production # this gates on manual approval
runs-on: ubuntu-latest
steps: [...]
On the cultural side The reason GitHub Flow doesn't stick at a lot of orgs isn't technical, it's that "we have dev/staging/prod" gets mentally collapsed with "we need a branch per environment". Separating those two conversations — "branches are about change isolation, environments are about deploy targets" — usually flips it. Show the team that |
Beta Was this translation helpful? Give feedback.
-
|
yeah github flow can totally work for dev, staging and production. I'd say the key thing is that your environments are controlled by your pipeline, not your branches. so you keep it simple with just main and feature branches but use github environments in your repo settings to handle the different stages the way i'd set it up is something like: opening a pr from a feature branch triggers a deploy to dev, merging into main auto deploys to staging, and then production gets triggered by a release or tag so you have control over when things go live the github environments feature is really what makes this work, you can add protection rules and require manual approvals before anything hits production which should help convince your team its not losing control, just moving the control to the pipeline instead of branches |
Beta Was this translation helpful? Give feedback.
-
|
Yes GitHub Flow can still support Dev/Staging/Prod if you keep main as the single source of truth and use deployments/promotions or release tags instead of long-lived branches; this keeps the flow simple while still matching environment needs, similar to how an MP4 video compressor reduces complexity by handling optimization without changing the original workflow structure. |
Beta Was this translation helpful? Give feedback.
-
|
I have been working on implementing what so many of you have said here, to learn how to use GitHub Flow. To that end I've created a simple repo which I made public, called Explore-Environments. I'm using 3 YAML files, somewhat tied to environments. One thing I've noticed is that all 3 YAML files ran, although the one for Production environment waited for me, since I had set that up in the Production environment to require a reviewer (me). And this is in keeping with what's been said in this forum thread. Note: that at this point I've only implemented the Production environment. I want to do both Develop and Staging next, for my edification. One thing I am not clear on is why did |
Beta Was this translation helpful? Give feedback.
-
|
I have gotten great feedback to my question. I wish I could mark all of you who've added to my understanding on this topic, but I don't think that's possible. So, I'm going to select the first answer and mark it as "the answer" but know I would select you all for your answer, if I could. Also, note that I am going to close this question as having been answered. I've got some follow-up questions, but I don't think it is right for me to tack them onto this question. I'll reference this question in my follow-up posts. |
Beta Was this translation helpful? Give feedback.
Hey @Rod-at-DOH
Great question, and honestly you're not alone in this struggle,a lot of teams get stuck thinking their branching strategy has to mirror their environments.
The good news is yes, GitHub Flow works perfectly fine with Dev, Staging, and Production. The key mindset shift is this: environments are controlled by your deployment pipeline, not your branches.
Here's how it maps practically:
Dev environment => triggered when a PR is opened from any feature branch
Staging => triggered automatically when that PR gets merged into main
Production => triggered by cutting a Release or Tag from main when you're ready
So main stays clean and is always your single source of truth. No painful…