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 8134229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:56:17+00:00 2026-06-06T09:56:17+00:00

how may I checkout a bare repository on my server in a post-receive hook

  • 0

how may I checkout a bare repository on my server in a post-receive hook that includes submodules?

I currently have this as a post-receive hook:

#!/bin/bash

# http://blog.ekynoxe.com/2011/10/22/git-post-receive-for-multiple-remote-branches-and-work-trees/
# post-receive hook that checks out development branch after a push to the bare
# repo

# paths must exist
livepath="/var/www/live"
devpath="/var/www/dev"

while read oldrev newrev ref
do
    branch=`echo $ref | cut -d/ -f3`

    #if [[ "master" == "$branch" ]]; then
    #   git --work-tree=$livepath checkout -f $branch
    #   echo 'Changes pushed live.'
    #fi
    if [[ "develop" == "$branch" ]]; then
        git --work-tree=$devpath checkout -f $branch
        echo 'Changes pushed to dev.'
    fi
done

But with this the submodules wont get initialized.

I tried doing this for testing manual:

cd /var/www/dev
git --work-tree /var/www/dev --git/dir /git/myrepo.git submodule init
git --work-tree /var/www/dev --git/dir /git/myrepo.git submodule update

submodule update command failed with this error messages:

fatal: working tree '/var/www/dev' already exists.
Clone of 'https://github.com/yiisoft/yii.git' into submodule path 'yii' failed

That behavior is already (unanswered) questioned here: Git submodules with separate work_tree

It would also be good if it would not reinitialize them if they are alredy there.

  • 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-06-06T09:56:21+00:00Added an answer on June 6, 2026 at 9:56 am

    --work-tree does not work well with submodules (becoz submodule need another repos, but it can’t put in your worktree). You need a separate clone for that.

    Just create a clone, do a cd + pull in your hook.

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

Sidebar

Related Questions

I have a corrupted loose object. I tried checkout, revert, rebase and may be
I have done a checkout of a number of Flex projects from a repository
I'm not entirely sure of the steps that caused this however I have ended
Whenever I commit, I worry that I may have missed out a dependency and
We have a local server with SVN installed on it that we are using
Magento Checkout process, the payment of page generally have this information: =========================================== Your the
may i know how to use this getMicrophone with simpleFLVWriter to create flv with
May I know what is the workaround to make this code passed, in Visual
I have one certain product that needs to be in the cart under certain
Suppose I have a git repos that contains original.script . At some point, I

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.