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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:35:50+00:00 2026-06-12T10:35:50+00:00

I have the following setup, I am working on a project project with the

  • 0

I have the following setup, I am working on a project project with the submodule submodule. Whenever I push changes to github it sends a post request to update.php on the server.

This php file executes a git command. Without submodules I can just do a git pull and everything is fine but with submodules it is much more difficult.

I have this at the moment, but it does not do what I want. I should git pull the repo and update and pull the latest version of each submodule.

<?php echo `git submodule foreach 'git checkout master; git pull; 
git submodule update --init --recursive; git commit -m "updating"' && git pull && 
git submodule foreach 'git add -A .' 
&& git commit -m "updating to latest version including submodules" 2>&1s`;

EDIT//
Okay, I got it half way done.

<?php echo `git submodule foreach 'git checkout master; git pull; 
git submodule update --init --recursive; git commit -am "updating"; echo "updated"' && 
git pull &&  git commit -am "updating to latest version including submodules" && 
echo 'updated'`;

The echo prevents the script to stop because of non-zero returned. It works 100% fine when I run it from the console using php update.php.

When github initialized the file, or I run it from the browser it still does not work.

Any ideas?

  • 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-12T10:35:52+00:00Added an answer on June 12, 2026 at 10:35 am

    Even if it would work there are things you should know about:

    1. If there are new submodules, you don’t init them. So you should start your script with git pull && git submodule update --init.

    2. git commit -am "updating" doesn’t create a new commit because you didn’t change anything in the submodule.

      • git checkout master only checks out branch master. This makes sense because of the otherwise detached head.

        Note: There might be repos where master is not the branch you want! See note below.

      • git pull fetches from the remote and merges the changes into master. Even if this is not a fast-forward merge¹, there’s nothing to commit as the merge commit is made automatically.

        ¹Because this is a checkout on your server there shouldn’t be a need for a non fast-forward merge. Otherwise you should think about merge conflicts and git push (see 3.), too!

      • git submodule update --init --recursive only fetches from the submodule’s submodule remotes and checks out the already referenced commits. So nothing new to commit here, either.

    3. If git commit -am "updating" would actually create a commit, the commit would be only available in the checked out version (fork), not in the referenced repository (see url = … in .gitmodules). So you commit references to submodule commit hashs in git commit -am "updating to latest version including submodules" that do not exist anywhere else.

      So in this case you would need to add a git push to your git submodule foreach '…'. See also here.

    4. As I mentioned in a comment to your question this workflow has one major disadvantage: Nobody tested the project files with the latest commits in the submodules. This might break the project!

    Try (indented for better readability):

    <?php echo `git pull &&
      git submodule update --init &&
      git submodule foreach 'git checkout master;
        git pull; 
        git submodule update --init --recursive;
        echo "updated"' && 
      git commit -am "updated submodules" && 
      echo 'updated'`;
    ?>
    

    Note on permissions:

    You said it works (with submodules) when using the php cli. Did you try this on your local machine or on the server? And if you did so on the server did you try it using the webserver’s account?

    Note on submodule branches:

    Using git checkout master (see 2.1) lets you only use the master branch of a submodule. To change this add update = rebase or update = merge to each entry in .gitmodules. (No detached head any more!) Then run git submodule foreach 'git checkout master' (or check out/create any other tracking branch) and you can simply use git submodule foreach 'git pull' from now on.

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

Sidebar

Related Questions

I am working on my first NHibernate project, and have the following setup/requirement. I
I have the following setup: eclipse a standard Java project (A) an eclipse plugin
I have a setup project that I'm working with and have added a EULA
I have the following setup active and working: Jenkins with Git and Sonar plugins
I have the following setup: I'm working with C++ projects under a custom build
Currently I am working on a project which has following setup. AVR micro-controller IDE
I have following setup, but when I put 1024 and replace all 512 with
I have following models setup in my Django application class School(models.Model): name = models.TextField()
I have the following setup: Table: Question QuestionId Table: QuestionTag QuestionId TagId Table: Tag
I have the following setup, and I need to know how to persist state.

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.