# How to manage multiple repositories

Today we’d like to share a few more helpers from our toolbox. We already shared our Makefile for Node.js Developers some time ago, these tools require the Makefile to be set up.

- **Author:** Patrick Heneise
- **Published:** 2018-04-13
- **Updated:** 2018-04-13
- **Tags:** git, javascript, nodejs, developer-experience, workflow-automation

---

### The Problem

Our projects start with 2–3 repositories and quickly grow to 5–10 or more. There
are several developers working on modules, front-end or backend services and you
may not be responsible or aware of what’s going on in the other repositories,
but you still need everything up-to-date on your laptop to run and test the
whole architecture.

### Our solution

We initially looked into “monorepo” tools like
[Lerna](https://github.com/lerna/lerna), but we found them to be overly complex
and storing everything in “packages” didn’t feel right. The one problem we
wanted to solve is keeping a few folders updated. The first thing we did was to
create a “root level” repository, we either call that “hq” or the same name as
the organisation/product we want to build. This repo we clone locally and add a
.gitignore:

```
/*
!bin/
!README.md
```

This ignores all contents in that repo except `bin` and `README.md`. Afterwards
we clone all related repositories for that project into the root folder.

The interesting part happens in bin/:

<script src="https://gist.github.com/PatrickHeneise/9fc4a2d760d16a3345fa294431ec8f58.js"></script>

The script loops through every folder and first prints the name of the folder.
This is important to see when an error happens on git pull. Afterwards, we check
out `package-lock.json` because this it the most common cause for a `git pull`
to fail. `--prune` also removes all stale branches that you might have locally,
keeping things clean and tidy. And last, we run `npm install` to update the
packages.

In the Makefile, just add those lines:

```
    git pull
    ./bin/update.sh
```

and you can run everything with `make update`. The whole process can take a
minute or two, but it’s great to keep all repos of a project updated.

It happened a few times that we forgot to checkout the master branch after
committing a pull request and the repo would never be updated with the update
script, so here is a little addition to quickly check if all repos are using the
`master` branch:

<script src="https://gist.github.com/PatrickHeneise/da4f79f5e4d6b566418263a1c84296ac.js"></script>

Again, this is most useful in the Makefile:

```
branches:
    ./bin/branches.sh
```

Enjoy this developer experience and let us know what you think! You can
[reach out on Bluesky](https://bsky.app/profile/zentered.co) or
[start a discussion on GitHub](https://github.com/zentered/zentered/discussions/new?category=ideas-feedback).
