Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6614397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:20:02+00:00 2026-05-25T20:20:02+00:00

Currently I deploy a project to production with git, using git push production master

  • 0

Currently I deploy a project to production with git, using git push production master to a repository with the following post-receive hook:

#!/bin/bash
GIT_WORK_TREE=/home/username/www.example.com/myproject/ git checkout -f

production is a remote, added via git remote add production ssh://server/home/username/projects/myproject.git.

But now I need to deploy a separate branch to a separate path on the server. I did come up with a solution, but I suppose there’s a better way to do it.

What I did was create a new repository on the server, myproject-alternate.git, with a similar post-receive hook (replacing /myproject/ with /myproject-alternate/), added this new repository with git remote add alternate ssh://server/home/username/projects/myproject-alternate.git. Now I can deploy to the alternate path with git push alternate branchname:master.

This works, but I have some issues:

  1. The command to deploy to the alternate server is not what I was expecting—more than once I forgot the :master at the end and the server’s repository received a new branch and the post-receive hook wasn’t triggered.
  2. I’m not sure if creating a new repository on the server was the best solution, and I wonder what would happen with a larger project.

Are there other ways to accomplish this deploy flow without the mentioned issues? Maybe a better post-receive hook that uses the received branchname to deploy to the right path? (is this even possible?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:20:04+00:00Added an answer on May 25, 2026 at 8:20 pm

    I’ve written a blog post about a setup I use to deploy my website to a staging server and the live server. You could do something similar. The key is to configure which branches you’re going to be pushing in the .git/config file of your local repository, something like this:

    [remote "alternate"]
        url = ssh://server/home/username/projects/myproject-alternate.git
        fetch = +refs/heads/master:refs/remotes/alternate/master
        pushurl = ssh://server/home/username/projects/myproject-alternate.git
        push = refs/heads/branchname:refs/heads/master
    [remote "production"]
        url = ssh://server/home/username/projects/myproject.git
        fetch = +refs/heads/master:refs/remotes/production/master
        pushurl = ssh://server/home/username/projects/myproject.git
        push = refs/heads/master:refs/heads/master
    

    This will set it up so that whenever you type

    git push alternate
    

    it will automatically push the local branchname branch to the remote master branch in the alternate repository.

    However, since your alternate and production work trees are on the same computer, you can probably get away with only creating one repository and just checking it out to two different places. To do that, ignore the previous paragraph, and instead put something like this in your post-receive hook:

    #!/bin/bash
    checkout_alt=
    checkout_prod=
    while read oldrev newrev refname; do
        case "$refname" in
            ( "refs/heads/branchname" )
                export checkout_alt=1 ;;
            ( "refs/heads/master" )
                export checkout_prod=1 ;;
        esac
    done
    test -n "$checkout_alt" && GIT_WORK_TREE=/home/diazona/tmp/gittest/alt/ git checkout -f branchname
    test -n "$checkout_prod" && GIT_WORK_TREE=/home/diazona/tmp/gittest/prod/ git checkout -f master
    

    (obviously you don’t have to use an if statement). If you do this, I suggest making the repository bare so that it doesn’t store its own working copy, just for simplicity. This way, you only need to have one remote, and whenever you push the master branch, it will update the production work tree, and whenever you push the branchname branch, it will update the alternate work tree.

    Disclaimer: I haven’t actually tested this, so try it out in a test folder first. If I find any errors I’ll come back and edit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently deploying a Rails application using Capistrano. Cap deploy:update_code usually works just
Currently we have a project with a standard subversion repository layout of: ./trunk ./branches
I am having four different project, and i am using Weblogic to deploy my
I'm currently trying to deploy an Ruby on Rails 3.0.9 app on a production
Being a Windows developer I'm currently working on my own project using LAMP. I
We currently deploy web applications by creating a database and running SQL scripts through
I'm currently getting the AccessControlException below when I deploy to app engine (I don't
Currently I'm doing some unit tests which are executed from bash. Unit tests are
I am currently trying to setup our complete development process (from dev to production).
I'm currently working on a symfony webapp, which is already on production. To develop

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.