Git post-receive deployment scriptSynchronizing git repository with post-receive hookAgent Forwarding Through...

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Risk of getting Chronic Wasting Disease (CWD) in the United States?

Why, historically, did Gödel think CH was false?

Languages that we cannot (dis)prove to be Context-Free

Expeditious Retreat

Theorems that impeded progress

Why are 150k or 200k jobs considered good when there are 300k+ births a month?

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

How is it possible to have an ability score that is less than 3?

Show that if two triangles built on parallel lines, with equal bases have the same perimeter only if they are congruent.

Why don't electron-positron collisions release infinite energy?

What do you call a Matrix-like slowdown and camera movement effect?

Arthur Somervell: 1000 Exercises - Meaning of this notation

What typically incentivizes a professor to change jobs to a lower ranking university?

Smoothness of finite-dimensional functional calculus

Font hinting is lost in Chrome-like browsers (for some languages )

How can bays and straits be determined in a procedurally generated map?

tikz: show 0 at the axis origin

Do VLANs within a subnet need to have their own subnet for router on a stick?

Which models of the Boeing 737 are still in production?

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

What is the offset in a seaplane's hull?

In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?

How do I create uniquely male characters?



Git post-receive deployment script


Synchronizing git repository with post-receive hookAgent Forwarding Through Different Usernames (Git & Deployment)Git corrupt master branchGit and (gitweb) and SVN both over HTTPS at same timeIssues with file ownership after git pushusing git pull after ssh in scriptGitlab 7.10 install doesn't create proper ssh git user config?Git push over SSH is not activating remote hooksSetting up GIT_WORK_TREE in git hooks dir on siteground hostinghow to create a the following bash script alias for git based deployment






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm writing a post-receive script that should deploy my code from my admin server to the correct production or testing environement on other servers inside a peering connection.



The post-receive should check which branch is pushed and if it's master then ssh to production server and deploy code to the correct folder.



I write a basic bash file but I can't figure out how to manage the git-dir(in admin server) and the work-tree(in production server):



#!/bin/bash
GIT_DIR="/git/domain.git"
TARGET_DIR="/var/www/vhosts/domain.com"

while read oldrev newrev ref
do
if [[ $ref = refs/heads/master ]];
then
echo "Loading repo.."
git --git-dir="$GIT_DIR"
echo "Connecting to production.."
ssh 10.120.10.63
echo "Ref master received. Deploying master branch to production server"
git --work-tree="$TARGET_DIR" checkout -f master
fi
done


How can this script be better writed?





[edit]



I try with another solution hoping git is smart enoough to open the path but the script return error and doesn't resolve the target_dir correctly



#!/bin/bash
GIT_DIR="/git/domain.git"
TARGET_DIR="ssh://user@10.120.10.63:/var/www/vhosts/domain.com"

while read oldrev newrev ref
do
if [[ $ref = refs/heads/master ]];
then
echo "Ref master received. Deploying master branch to production server"
git --git-dir="$GIT_DIR" --work-tree="$TARGET_DIR" checkout -f master
fi
done









share|improve this question































    0















    I'm writing a post-receive script that should deploy my code from my admin server to the correct production or testing environement on other servers inside a peering connection.



    The post-receive should check which branch is pushed and if it's master then ssh to production server and deploy code to the correct folder.



    I write a basic bash file but I can't figure out how to manage the git-dir(in admin server) and the work-tree(in production server):



    #!/bin/bash
    GIT_DIR="/git/domain.git"
    TARGET_DIR="/var/www/vhosts/domain.com"

    while read oldrev newrev ref
    do
    if [[ $ref = refs/heads/master ]];
    then
    echo "Loading repo.."
    git --git-dir="$GIT_DIR"
    echo "Connecting to production.."
    ssh 10.120.10.63
    echo "Ref master received. Deploying master branch to production server"
    git --work-tree="$TARGET_DIR" checkout -f master
    fi
    done


    How can this script be better writed?





    [edit]



    I try with another solution hoping git is smart enoough to open the path but the script return error and doesn't resolve the target_dir correctly



    #!/bin/bash
    GIT_DIR="/git/domain.git"
    TARGET_DIR="ssh://user@10.120.10.63:/var/www/vhosts/domain.com"

    while read oldrev newrev ref
    do
    if [[ $ref = refs/heads/master ]];
    then
    echo "Ref master received. Deploying master branch to production server"
    git --git-dir="$GIT_DIR" --work-tree="$TARGET_DIR" checkout -f master
    fi
    done









    share|improve this question



























      0












      0








      0


      1






      I'm writing a post-receive script that should deploy my code from my admin server to the correct production or testing environement on other servers inside a peering connection.



      The post-receive should check which branch is pushed and if it's master then ssh to production server and deploy code to the correct folder.



      I write a basic bash file but I can't figure out how to manage the git-dir(in admin server) and the work-tree(in production server):



      #!/bin/bash
      GIT_DIR="/git/domain.git"
      TARGET_DIR="/var/www/vhosts/domain.com"

      while read oldrev newrev ref
      do
      if [[ $ref = refs/heads/master ]];
      then
      echo "Loading repo.."
      git --git-dir="$GIT_DIR"
      echo "Connecting to production.."
      ssh 10.120.10.63
      echo "Ref master received. Deploying master branch to production server"
      git --work-tree="$TARGET_DIR" checkout -f master
      fi
      done


      How can this script be better writed?





      [edit]



      I try with another solution hoping git is smart enoough to open the path but the script return error and doesn't resolve the target_dir correctly



      #!/bin/bash
      GIT_DIR="/git/domain.git"
      TARGET_DIR="ssh://user@10.120.10.63:/var/www/vhosts/domain.com"

      while read oldrev newrev ref
      do
      if [[ $ref = refs/heads/master ]];
      then
      echo "Ref master received. Deploying master branch to production server"
      git --git-dir="$GIT_DIR" --work-tree="$TARGET_DIR" checkout -f master
      fi
      done









      share|improve this question
















      I'm writing a post-receive script that should deploy my code from my admin server to the correct production or testing environement on other servers inside a peering connection.



      The post-receive should check which branch is pushed and if it's master then ssh to production server and deploy code to the correct folder.



      I write a basic bash file but I can't figure out how to manage the git-dir(in admin server) and the work-tree(in production server):



      #!/bin/bash
      GIT_DIR="/git/domain.git"
      TARGET_DIR="/var/www/vhosts/domain.com"

      while read oldrev newrev ref
      do
      if [[ $ref = refs/heads/master ]];
      then
      echo "Loading repo.."
      git --git-dir="$GIT_DIR"
      echo "Connecting to production.."
      ssh 10.120.10.63
      echo "Ref master received. Deploying master branch to production server"
      git --work-tree="$TARGET_DIR" checkout -f master
      fi
      done


      How can this script be better writed?





      [edit]



      I try with another solution hoping git is smart enoough to open the path but the script return error and doesn't resolve the target_dir correctly



      #!/bin/bash
      GIT_DIR="/git/domain.git"
      TARGET_DIR="ssh://user@10.120.10.63:/var/www/vhosts/domain.com"

      while read oldrev newrev ref
      do
      if [[ $ref = refs/heads/master ]];
      then
      echo "Ref master received. Deploying master branch to production server"
      git --git-dir="$GIT_DIR" --work-tree="$TARGET_DIR" checkout -f master
      fi
      done






      bash ssh git






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday







      Mindexperiment

















      asked yesterday









      MindexperimentMindexperiment

      111




      111






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1421874%2fgit-post-receive-deployment-script%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1421874%2fgit-post-receive-deployment-script%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...

          Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

          VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...