Updating Multiple Repos With One Command

Jorge Yau
1 min readMar 23, 2017

--

find . -maxdepth 3 -name .git -type d | rev | cut -c 6- | rev | xargs -I {} git -C {} pull

Breakdown

This command will find all git repos in your current directory with a max depth of 3. Afterwards it will perform a git pull on the current branch for each of those repositories.

Further Tips

First, I recommend creating a bash alias for this command. Add this to your .bashrc on Linux or .bash_profile on Mac. Then restart your terminal.

alias git-pull-all="find . -maxdepth 3 -name .git -type d | rev | cut -c 6- | rev | xargs -I {} git -C {} pull"

Then you can just run

$ git-pull-all

If you encounter password prompts, I recommend setting up SSH keys with your Git hosting service (GitHub, BitBucket, etc) to make the process as seamless as possible. It’s super easy and takes less than five minutes.

The last tip is to use a post-merge git hooks to automatically perform package updates, e.g. npm install or pip install. Read the instructions here.

Thank you for reading! Please like this article if you found it useful. This tutorial is part of my Git Fundamentals series, which aims to maximize your productivity with git. You can read more about it here.

https://hackernoon.com/5-git-fundamentals-ded819a34cfe

--

--

Jorge Yau

Senior Web Engineer at Stash. I write about NYC, tech, and the immensity of life.