Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I init/update a git submodule in a working tree after pushing to a bare working directory?

I have a git repository with an attached working tree that I'm pushing to a bare repo on a remote. The repository includes a submodule.

At the remote end: I check out the repo to a working tree git checkout -f having set GIT-DIR and GIT-WORK-TREE env vars.

In the working tree I now see all the expected files and an empty directory for the submodule ('MySubmodule').

I then do:

git submodule init
git submodule update

This errors with a message like:

working tree '../../workTree/' already exists
Clone of '[email protected]:user/MySubmodule.git' into submodule path 'MySubmodule' failed

The empty submodule directory has now also 'vanished' from the working tree...

I'm not sure where I'm going wrong with this, basically I just want to check out the submodule files as I would with 'git submodule update'.

like image 248
arlogb Avatar asked Sep 16 '11 15:09

arlogb


People also ask

How do I initialize a git submodule?

If you already cloned the project and forgot --recurse-submodules , you can combine the git submodule init and git submodule update steps by running git submodule update --init . To also initialize, fetch and checkout any nested submodules, you can use the foolproof git submodule update --init --recursive .

What is git submodule update -- init -- recursive?

git submodule update --init --recursive --remote - updates all submodules recursively along their tracking branches. Without the --remote , it'll reset the submodule working directories to the "right" commit for the parent.


1 Answers

It looks like when your running "git submodule update" you can't set the GIT_WORK_TREE... it will try to use this as the working tree for the submodule, not for the super project.

I've had to update my servers post-update script...

/usr/local/bin/git --git-dir="$PROJECT_DIR" --work-tree="$PROJECT_DEMO" checkout -f;

cd "$PROJECT_DEMO";
/usr/local/bin/git --git-dir="$PROJECT_DIR" submodule update --init --recursive;

Notice I didn't set env variables, and that the submodule command did not have the "--work-tree" set... it seems that it needs to work from the cwd.

like image 125
Craig Francis Avatar answered Oct 23 '22 13:10

Craig Francis