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

daugaard47's avatar

How to Push a GIT Branch to a Live Testing server

As the title states, I want to figure out a workflow to test my GIT Branches on a Live server before merging to master and pushing to production.

This is my current GIT Workflow:

I should note on my server the repo's are in /var/repo/dev.git and /var/repo/site.git and sync to my /var/www/(dev & site folder)

Here is the folder structure:

folder stucture

Inside dev.git and site.git

#HEAD
ref: refs/heads/master
---------
#CONFIG:
[core]
    repositoryformatversion = 0
    filemode = true
    bare = true

Inside the folder refs there is a folder called heads and a file called master. There are also other files that are named the same name as my branches I've tried to push.

branches

For simple changes:

  1. I work directly on the Master Branch, Locally.
  2. Then Push to a Live Staging server dev.example.com to make sure everything is running smooth
  3. Then push the master to the Live Production server example.com
git status
git add *
git commit -m "My Change"
git push // Pushes to Master Branch on Git Hub
git push staging // Pushes to my live staging server
git push production // Pushes to my live production server

For Branches:

  1. I create a new branch locally git checkout -b newbranch.

  2. Then Push to newly created branch on GitHub git push origin newbranch

  3. When on the newbrach I push to GitHub then try and push to git push staging or git push staging newbranch, but no changes are made to my staging/dev server

  4. So I have to git everything working on that branch locally

  5. Merge to the Master Branch

  6. Then push to Staging and hope all is working smoothly

  7. The push to Production

I want to figure out how to Push my working branch to my Live staging server so I can run Live Tests. Then Merge to Master and Push to Production.

Here is a nice little diagram of what I'm currently doing and what I want to do.

Note, I want to do illustration #3 in the diagram. enter image description here

0 likes
3 replies
jonassiewertsen's avatar

You can do it by using a post-receive hook.

Short form:

  1. Create an empty git on your server, via git --init --bare
  2. Create the post receive hook
  3. Add a remote repository on your local machine
  4. Then push to your remote repository (you can select a brach for the hook)

Your will find more detailed informations here: https://gist.github.com/Nilpo/8ed5e44be00d6cf21f22

daugaard47's avatar

On my server In /var/repo/dev.git/hooks/post-receive I have the following:

git --work-tree=/var/www/dev --git-dir=/var/repo/dev.git checkout -f

This is what I use to push my master to live development server. Git push staging

Do I need to change this post-receive hook?

daugaard47's avatar

Seems like the best flow is creating a master branch and a develop branch approach.

Develop branch would then push to staging server.

Develop branch can also have multiple branches: IE feature/newfeature branch

Once feature/newfeature branch is good on local;

  • merge to develop.
  • Then push develop to staging server to test live or to show client new feature(s)
  • After that, merge develop to master and push to production.

Looks like Gitflow has some helpful commands to make this process a little smoother.

Please or to participate in this conversation.