David Marks
David Marks

Reputation: 266

Pulling git submodules with TortoiseGit

I'm using TortoiseGit to maintain git repository. We have one repo with multiple submodules in each. Everything works fine but when I'm trying to pull main repo, submodules aren't updating. I must pull every submodule one by one.

Is there an option in tortoise to use only one pull command from menu to update all changes in all submodules for repo?

Upvotes: 23

Views: 22609

Answers (3)

Chris Moschini
Chris Moschini

Reputation: 37967

Update

There is now a way to do this in TortoiseGit, which the other answer covers; old script approach that can be useful for automation scripts below.

Old Edit

There is no current way to do this in TortoiseGit, although I've found the author is very responsive to good ideas if you submit them as clear Feature Requests. Here's how I cope with this issue:

In every new project with submodules, I dump the following 2 scripts into the root:

gitsetup.sh

#!/bin/bash
# git built-in
echo "Setting up submodules"
git submodule update --init

echo "Setting up submodules for TortoiseGit/Putty"
# 1) Find the puttykeyfile line, like
#         puttykeyfile = C:\\Users...\\.ssh\\PuTTY.ppk
# 
# in .git/config

# pass to sed to double-escape all backslashes (Windows problem) - that way
# it doesn't become an issue when we use it in sed
puttyline="$(grep puttykeyfile .git/config | sed 's/\\/\\\\/g')"

# 2) Search for .git/modules/*/config

files=$(find .git/modules -type f -name config)

# 3) Find [remote "origin"] 
# 4) Insert line (entire puttykeyfile line we picked up earlier)

echo 'Inserting missing TortoiseGit .ppk into submodules:'

for file in $files
do
    # -q says don't print the grep results, just return 0 or 1
    if grep -q putty $file
    then
        # I have no idea how to just say if not grep, so screw it here's an empty then
        /dev/null
    else
        echo $file
        # -i means overwrite the file rather than printing the result to
        # stdout
        sed -i "s/\(\[remote .origin.\]\)/\1\n$puttyline/" $file
    fi
done

gitpullall.sh

#!/bin/bash -v
git pull --recurse-submodules
git submodule update --recursive

or if you'd prefer to fetch HEAD on your submodules, not the commit the parent repo was checked in with:

gitpullallhead.sh:

git submodule foreach git pull origin master

Here's what they do:

When someone else pulls your project down via TortoiseGit, they're going to have worse than needing to pull all submodules - they won't even have those submodules configured. Worse, if they attempted to set them up:

  1. TortoiseGit is just going to get in their way - it doesn't really have anything to cope with this problem yet.
  2. They'll use the command line, which will point each submodule at its repo but not associate it with your Tortoise/PuTTY key like a normal Pull would.

So, if they just run gitsetup.sh, it takes care of all of that - it sets up each submodule, pulls it, and even inserts the special .ppk (PuTTY key) config setting into each one. Works in any project - no need to tweak it each time.

gitpullall.sh does just what you think, it goes and fetches everything.

So, not strictly a TortoiseGit solution (that doesn't exist), but still convenient enough.

As is likely evidenced by the comments in those scripts, I am no Bash professional and clearly hacked them together. I welcome suggestions for improvements especially in the most obvious places. But I assure you they not only work but work across several of our projects with numerous submodules stored at several directory levels.

Old answer:

Something like:

for module in a b c d; do cd $module; git pull; cd..; done

Upvotes: 2

Ian G
Ian G

Reputation: 5526

I was also able to just right-click on the folder that was the submodule and do a normal Git Pull on that folder.

This pulled just the submodule - so slightly simpler than the (admittedly great) answer above for a single submodule.

Upvotes: 2

linquize
linquize

Reputation: 20406

(git 1.8.2 or later)

  1. git pull

  2. git submodule update --merge --remote

Here are the corresponding screens of TortoiseGit to perform the task.

enter image description here

enter image description here

enter image description here

Upvotes: 38

Related Questions