Skip to content

Instantly share code, notes, and snippets.

@djallits
Created June 15, 2026 20:50
Show Gist options
  • Select an option

  • Save djallits/6bfdaab8bfe072f8bef4d1ab9b1d0018 to your computer and use it in GitHub Desktop.

Select an option

Save djallits/6bfdaab8bfe072f8bef4d1ab9b1d0018 to your computer and use it in GitHub Desktop.
GitHub Local Update
#!/usr/bin/env bash
set -euo pipefail
owners=(
"bissell-inc"
"{{USERNAME}}"
)
base_dir="${BASE_DIR:-.}"
for owner in "${owners[@]}"; do
echo "==> Syncing repositories for ${owner}"
mkdir -p "${base_dir}/${owner}"
gh repo list "${owner}" \
--limit 1000 \
--json name,sshUrl \
--jq '.[] | [.name, .sshUrl] | @tsv' |
while IFS=$'\t' read -r repo ssh_url; do
repo_dir="${base_dir}/${owner}/${repo}"
if [[ ! -d "${repo_dir}/.git" ]]; then
echo "Cloning ${owner}/${repo}..."
git clone "${ssh_url}" "${repo_dir}"
else
echo "Updating ${owner}/${repo}..."
git -C "${repo_dir}" remote set-url origin "${ssh_url}"
fi
git -C "${repo_dir}" fetch origin \
'+refs/heads/*:refs/remotes/origin/*' \
'+refs/tags/*:refs/tags/*' \
--prune \
--prune-tags
default_branch="$(
git -C "${repo_dir}" remote show origin |
awk '/HEAD branch/ { print $NF }'
)"
if [[ -n "${default_branch}" ]]; then
git -C "${repo_dir}" checkout "${default_branch}" 2>/dev/null ||
git -C "${repo_dir}" checkout -b "${default_branch}" "origin/${default_branch}"
git -C "${repo_dir}" pull --ff-only origin "${default_branch}"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment