-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpull-submodules.sh
More file actions
executable file
·36 lines (27 loc) · 1.1 KB
/
pull-submodules.sh
File metadata and controls
executable file
·36 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# A script to iterate through all Git submodules, check out their default branch,
# and pull the latest changes.
#
# USAGE:
# ./pull-submodules.sh
# --- Main Logic ---
echo "Starting to pull updates for all submodules..."
echo "-------------------------------------------------"
# Use git submodule foreach to iterate through each submodule directory.
git submodule foreach '
# The $path variable is automatically provided by `git submodule foreach`.
echo "=> Processing submodule: $path"
# Find the default branch name from the remote (e.g., main, master).
# This is a robust way to handle submodules with different default branches.
DEFAULT_BRANCH=$(git symbolic-ref --short refs/remotes/origin/HEAD | sed "s@^origin/@@")
if [ -n "$DEFAULT_BRANCH" ]; then
echo " Switching to default branch: $DEFAULT_BRANCH"
git checkout "$DEFAULT_BRANCH"
echo " Pulling latest changes..."
git pull
else
echo " Could not determine the default branch for $path. Skipping."
fi
echo "-------------------------------------------------"
'
echo "Submodule pulling complete."