Skip to content

Instantly share code, notes, and snippets.

@J00MZ
Last active July 14, 2025 14:27
Show Gist options
  • Save J00MZ/3f7d0b7fbeb1060c88a1f1e229a30f85 to your computer and use it in GitHub Desktop.
Save J00MZ/3f7d0b7fbeb1060c88a1f1e229a30f85 to your computer and use it in GitHub Desktop.
Pull All Repos Command
# 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
@guychouk
Copy link

guychouk commented Jan 10, 2022

Awesome alias, thank you!

If you want, I wrote a one-liner that achieves pretty much the same (without error handling and messages of course 😉).

It works by running find from the parent directory of your Git projects, iterates all sub-directories and simply attempts to git pull each one, showing the sub-directory in red:

find . -type d -maxdepth 1 | xargs -I{} zsh -c 'echo "\u1b[31m{}\033[m" && cd {} && git pull'

@J00MZ
Copy link
Author

J00MZ commented Jan 12, 2022

Nice @guychouk !
Yours does lend itself much easier to implementation in parallel with a tool like GNU parallel like so:

find . -type d -maxdepth 1 | parallel zsh -c 'echo "\u1b[31m{}\033[m" && cd {} && git pull'

I do prefer the longer safer version though 😄

@guychouk
Copy link

@J00MZ Oooohh I love the use of parallel!
Thank you, adding it to my alias!

@J00MZ
Copy link
Author

J00MZ commented Jan 13, 2022

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