Last active
January 17, 2023 18:41
-
-
Save J00MZ/3f7d0b7fbeb1060c88a1f1e229a30f85 to your computer and use it in GitHub Desktop.
Pull All Repos Command
This file contains 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 | |
} | |
# Version 2 - fetch only, all repos in parallel | |
function pull_all_repos(){ | |
CURRENT_DIR="$(pwd)" | |
REPODIR="${1:-$(cdr && pwd)}" | |
REPOLOCATION="$(dirname "${REPODIR}")/$(basename "${REPODIR}")" | |
echo "Pulling latest in [${REPOLOCATION}]" | |
REPOLIST=$(find "${REPODIR}" -maxdepth 2 -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' | |
GL='git pull' | |
parallel --no-notice --bar --eta -j "${REPOLIST_LENGTH}" --tag \ | |
"echo 'Pulling latest from {}'; cd ${REPODIR}/{} && eval ${GFA} && eval ${GL}" ::: "${REPOLIST}" | |
cd "${CURRENT_DIR}" || exit | |
} | |
alias gfa='git fetch --all --prune --jobs=10' | |
alias cdr='cd ${HOME}/code/repos' | |
alias pullall="pull_all_repos" | |
alias fetchall="fetch_all_repos" |
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 😄
@J00MZ Oooohh I love the use of parallel
!
Thank you, adding it to my alias!
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
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 togit pull
each one, showing the sub-directory in red: