Local Makefile without polluting the project

2026-03-13

post-thumb

In every personal project of mine, the first thing I do is create a Makefile with the commands I use most. make server, make test, make build. I never need to remember anything, I just look at the Makefile and I’m good.

At the company I work for, we use Nx and there’s no Makefile. The commands are all via npx nx. They work fine, but I wanted to keep my usual workflow: open the terminal and run make server.


The problem

I can’t just create a Makefile in the project. That would be polluting the repository with personal config. I also can’t add Makefile to the project’s .gitignore for the same reason.

And I can’t put Makefile in the global ignore (~/.gitignore) because I use Makefile in all my personal projects and commit them.


The solution

I created a personal convention: use the name local.mk for local Makefiles. I added local.mk to my global ~/.gitignore, and overrode the make command in my personal Oh-My-Zsh aliases.zsh:

make() {
  if [[ -f local.mk && $# -gt 0 ]]; then
    command make -f local.mk "$@"
  else
    command make "$@"
  fi
}

If a local.mk exists in the current directory and I pass arguments, it uses the local file. If it doesn’t exist, it runs make normally. Personal projects with a Makefile keep working as always.


In practice

At the company project, I created a local.mk with the commands I need:

.PHONY: server db api

server:
	trap 'kill 0' INT TERM; npx nx up db & sleep 5 && npx nx serve api & wait

db:
	npx nx up db

api:
	npx nx serve api

Now I run make server and it brings up the database and the API at once. make db starts only the database. make api starts only the API. All within the workflow I’m already used to, without touching anything in the repository.