Last active
July 14, 2025 14:27
-
-
Save J00MZ/3f7d0b7fbeb1060c88a1f1e229a30f85 to your computer and use it in GitHub Desktop.
Pull All Repos Command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version 1 - one repo at a time | |
function pull_all_repos(){ | |
CURRENT_DIR="$(pwd)" | |
DIRLIST=($(cdr && ls -1|xargs)) | |
REPODIR="$(cdr && pwd)" | |
for dir in "${DIRLIST[@]}";do | |
echo "Pulling latest from [${dir}]" | |
(cd "${REPODIR}/${dir}" && gfa) || echo "Failed to access ${dir}" | |
done | |
cd "${CURRENT_DIR}" || exit | |
} | |
export DIRLIST="LIST" | |
alias pullall="pull_all_repos" | |
❯ pullall | |
# Version 2 - all repos in parallel, requires gnu parallel and coreutils installed on Mac | |
# brew install parallel coreutils | |
function pull_all_repos () { | |
CURRENT_DIR="$(pwd)" | |
REPODIR="${1:-$(cd $HOME/Documents && pwd)}" | |
REPOLOCATION="$(dirname "${REPODIR}")/$(basename "${REPODIR}")" | |
echo "Pulling latest in [${REPOLOCATION}]" | |
REPOLIST=$(find "${REPODIR}" -maxdepth 2 -mindepth 1 -name .git -type d -print| sed 's/.git//'|xargs -I {} basename {}|sort) | |
REPOLIST_LENGTH="$(echo "${REPOLIST}"|wc -w|xargs)" | |
GFA='git fetch --all --prune --jobs=10' | |
GBDA="git branch --merged|grep -v '*'|grep -v main|xargs -I {} git branch -d {}" | |
GL='git pull --all --prune --jobs=10' | |
GFM='git fetch origin main:main' | |
gtimeout 1m parallel --no-notice --bar --eta -j "${REPOLIST_LENGTH}" --tag "echo 'Pulling latest from {}'; cd ${REPODIR}/{} && eval ${GFA} && (eval ${GL} || eval ${GFM}) && eval ${GBDA}" ::: "${REPOLIST}" | |
cd "${CURRENT_DIR}" || exit | |
} | |
alias pullall="pull_all_repos" | |
❯ pullall |
Make sure to approve the citation on first use using parallel --will-cite
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@J00MZ Oooohh I love the use of
parallel
!Thank you, adding it to my alias!