Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pekkagaiser's avatar

Deploying from git to a stage and production environment

This is really a git question. Hope that is allowed here. I'm currently learnign Laravel and have created a first test project running locally.

I also have a location for the production version of the project and a basic Github-based deployment workflow: when I have tested code changes locally, I push them to a Github repo, which get deployed by SSH to the production server using Github Actions.

However, I would also like to have a staging environment for the project that is online, on a separate server. The idea being that I first test code changes locally; then push them to the staging environment and run some tests; and if that all checks out, I push to the production environment.

I still don't really understand branching and tagging in Git. What are some good ways to do this? Does one create a "production" and a "staging" branch and push to each?

I know (or can find out) how to setup a Github Action to deploy from a tag or branch. My question really is about how to organize this within git so I can easily push a change to the staging environment, and as easily to production.

Would appreciate a step-by-step explanation, or any pointers to tutorials...

0 likes
7 replies
christian-qode's avatar

Yes, best way is to create a "production" and "staging" branch for both environments and have different deployments for each branch.

1 like
click's avatar

I like "Git Flow" however I see a note on the website of the "owner" that he suggests a simpler flow but it is all up to you .

Atlassians Git Tool called Sourcetree has a build in flow for it which allows you to just press some buttons to follow the flow.

It looks scary at first bit if you do it step by step it works great (in my case).

When working on a new feature/ticket you create a branch from develop. When you are done with the ticket you merge it back to develop. When you are ready to create a release (for testing/staging) you create a new branch from develop called release/0.1 (or whatever number you want to use). When you / your stakeholders are happy with the release you tag it as 0.1.

https://nvie.com/posts/a-successful-git-branching-model/

1 like
pekkagaiser's avatar

@click thank you, will check this out and try to implement it! Any more serious dealings with Git than just committing and pushing tend to give me headaches 😂

PovilasKorop's avatar
Level 11

@pekkagaiser https://youtu.be/AmScEC-_72I this is my video on the topic.

In simple situation, in short.

  1. You create a new branch "develop" from main/master
  2. Locally you only work with develop branch and push its changes
  3. Separate server/environment to test the code by deploying from that develop branch
  4. When you feel it's tested and ready to go live, pull request from develop to main/master, merge it and then deploy to live, from main/master.
1 like
pekkagaiser's avatar

@PovilasKorop This was the breakthrough after pointlessly fighting with "git rebase" for a couple hours 😂 thank you.

1 like

Please or to participate in this conversation.