-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-github-repos.sh
More file actions
executable file
·49 lines (41 loc) · 1.12 KB
/
sync-github-repos.sh
File metadata and controls
executable file
·49 lines (41 loc) · 1.12 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# SPDX-License-Identifier: PMPL-1.0-or-later
# Sync all GitHub repos locally
set -euo pipefail
REPO_DIR="${HOME}/repos"
mkdir -p "$REPO_DIR"
echo "=== Fetching repo list from GitHub ==="
REPOS=$(gh repo list --limit 200 --json name,sshUrl --jq '.[] | "\(.name)|\(.sshUrl)"')
TOTAL=$(echo "$REPOS" | wc -l)
CLONED=0
PULLED=0
FAILED=0
echo "Found $TOTAL repos on GitHub"
echo ""
while IFS='|' read -r name url; do
target="${REPO_DIR}/${name}"
if [[ -d "$target/.git" ]]; then
echo "[PULL] $name"
if git -C "$target" pull --ff-only 2>/dev/null; then
((PULLED++))
else
echo " -> Pull failed, trying fetch..."
git -C "$target" fetch --all 2>/dev/null || true
((PULLED++))
fi
else
echo "[CLONE] $name"
if git clone --depth 1 "$url" "$target" 2>/dev/null; then
((CLONED++))
else
echo " -> Clone failed: $name"
((FAILED++))
fi
fi
done <<< "$REPOS"
echo ""
echo "=== Summary ==="
echo "Cloned: $CLONED"
echo "Pulled: $PULLED"
echo "Failed: $FAILED"
echo "Total: $TOTAL"