Batch Pull All Your Local Git Repositories with a One‑Liner Script
This guide shows how to locate every .git directory within a few levels, trim the paths, and run git pull on each repository using a single pipeline command that can also be saved as a convenient shell alias.
Keeping dozens of local Git repositories up to date manually is time‑consuming; the article presents a compact shell pipeline that automatically finds each repository and runs git pull for you.
The core command is:
find . -maxdepth 3 -name .git -type d | rev | cut -c 6- | rev | xargs -I {} git -C {} pullIt works in three stages:
Locate all .git folders
The find part searches the current directory (and up to three sub‑levels) for directories named .git:
find . -maxdepth 3 -name .git -type d .– start from the current directory -maxdepth 3 – descend at most three directory levels -name .git – match entries named
.git -type d– restrict matches to directories
Trim the trailing .git from each path
The pipeline rev | cut -c 6- | rev reverses each path string, removes the first six characters (the reversed .git), and reverses the result back, leaving only the repository’s root directory.
... | rev | cut -c 6- | rev | ... rev– reverse the string cut -c 6- – drop the first six characters (the reversed .git) rev – reverse again to restore the original order
Run git pull in each repository
Because git does not accept a directory argument directly, xargs feeds each trimmed path to git -C {path} pull: xargs -I {} git -C {} pull This effectively executes git pull inside every discovered repository.
Convenient alias
To avoid typing the long pipeline each time, add the following alias to .zshrc or .bash_profile:
alias gpall="find . -maxdepth 3 -name .git -type d | rev | cut -c 6- | rev | xargs -I {} git -C {} pull"After reloading the shell, simply run gpall to update all repositories at once.
References
Updating Multiple Repos With One Command
xargs command tutorial
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
