Git pull multiple repositories at once
Tags: git, learning, showdev, productivity
Published: 2019-12-03 17:10:26

---
title: Git pull multiple repositories at once
published: true
description: Pull as many repositories are there on one directory
canonical_url: https://gabac.blog/posts/git-pull-many-repos-at-once/
tags: git, learning, showdev, productivity 
---

**Update:** I wrote about another approach to achieve this and some extras, with git submodules. You can find it here [here](https://dev.to/rmpato/a-new-use-case-for-git-submodules-3do1).
--
  

I usually work with many repos at the same time and generally group them within a same directory, named after the company. 

In example, if I'm working for "Great Employer INC." I'll have a directory probably named `greatemployerinc` and one directory for each repo I work within. Something like:

```
greatemployerinc
├── greatemployerinc-web
├── greatemployerinc-auth
├── greatemployerinc-core-service
├── greatemployerinc-email-service
├── ...more repos
└── greatemployerinc-gateway

```

Instead of navigating each one of them with `cd` and then manually run `git pull branch`, I came out with the following command that I run from `greatemployerinc` -the repos containing directory.

```
find . -mindepth 1 -maxdepth 1 -type d -print -exec git -C {} pull \;
```

It will find any subdirectory in the current one (greatemployerinc), without going deeper than the first level (delimited by mindepth 1 and maxdepth 1) and execute  a `git pull` in the corresponding git dir (if its a repo). 

>If you want to see more on the `git -C` option, you can check [this post on SO](https://stackoverflow.com/questions/5083224/git-pull-while-not-in-a-git-directory) 

Keep in mind it will run a *git pull* on the current branch that each repository is actually stepping on. Also, consider the pull might fail if you have pending changes (it will be shown on the console output, anyway) and you might need to handle those cases manually, or considering adding an `--autostash` option to the provided command. 

## Wait, I can't memorize that command!
Then you and I have something in common :) 

To avoid memorizing it, I created an alias. If you are working with ZSH you can just add this line to your `~/.zshrc` file

```
alias multipull="find . -mindepth 1 -maxdepth 1 -type d -print -exec git -C {} pull \;"
```

Then close your current terminal and open a new one (so the changes on `.zshrc` take effect), go to your equivalent `greatemployerinc` directory and do:

```
multipull
```

And drink your favorite infusion while your repos pull from remote :) 

### Conclusion

So, we created a quick small command to run a pull in multiple repos at once, then we created an alias for it so it is more easy to run later. 

If you are willing to take it further, you can tweak it a little bit around if you want to customize the branch you pull from/into, run a different command, or try and make it run in parallel.


### Updates

If you are interested on "resourcing" your terminal without closing/opening it, see [this comment from JPBlancoDB] (https://dev.to/jpblancodb/comment/ieo3) 

If you are interested on more complex scenarios, you can use a tool like `myrepos` just like [Caleb Maclennan points out in this comment](https://dev.to/alerque/comment/igbd)