Skip to main content

Makefile – A Simple Way to Automate Your Commands

Have you ever found yourself typing the same long command again and again in a project, and thought…
"Life would be so much easier if I didn’t have to type this every single time"?

That’s exactly where a Makefile can help you.


What is a Makefile?

A Makefile is just a plain text file where you define shortcuts for your commands.
It tells the make command what to do when you type something like:

make up

Instead of writing the whole long command every time, you just run make with the shortcut you defined.


A Simple Example

Let’s say you’re working with Docker and the command to start your app looks like this:

docker-compose -f docker-compose.development.yml up

Typing this again and again is boring. Instead, create a file named Makefile in your project root and add this:

up: docker-compose -f docker-compose.development.yml up

Now, all you need to do is run:

make up

Boom! Much shorter, much cleaner.


Adding More Commands

You can add as many shortcuts as you want inside your Makefile. For example:

up: docker-compose -f docker-compose.development.yml up down: docker-compose -f docker-compose.development.yml down logs: docker-compose -f docker-compose.development.yml logs -f
  • make up → Starts your containers

  • make down → Stops your containers

  • make logs → Shows real-time logs

This way, you don’t need to remember or re-type all the Docker flags.


Why Use Makefile?

  • Saves time → No more copy-pasting long commands.

  • Consistency → Your teammates can use the same shortcuts.

  • Not just for Docker → Works with anything (Rails, Node.js, tests, deployment).

  • Cross-platform → Works on Linux, macOS, and Windows (with tools like WSL).


Going Beyond Basics

Using Variables

Instead of repeating the same file name, you can store it in a variable:

FILE = docker-compose.development.yml up: docker-compose -f $(FILE) up down: docker-compose -f $(FILE) down

Now if you switch to another compose file, you only need to change it in one place.


Phony Targets

Some commands don’t create files (like up or down). To avoid confusion, add this at the top:

.PHONY: up down logs

This tells Make these are just shortcuts, not actual files.


Real-World Uses

Makefiles are super flexible. Apart from Docker, you can use them to:

  • Run tests

    test: pytest
  • Build a Rails app

    migrate: bin/rails db:migrate
  • Deploy your project

    deploy: git push heroku main

Basically, if it’s a command you type often → put it in a Makefile.


Conclusion

A Makefile is one of those small tools that make a huge difference in your daily workflow.
It’s simple, flexible, and saves you from typing the same commands again and again.

Next time you catch yourself repeating a long command, stop and think:
"Wait… should this go in my Makefile?"

Chances are, the answer is yes. 🚀


Comments

Popular posts from this blog

100 Reasons to Stay Alive — Small Joys & Big Why’s

Life can feel heavy sometimes. When it does, a simple reminder of what makes living meaningful can help. This list mixes small comforts and long-term goals — plus a few short anecdotes — to pull you back when the weight feels too much. Keep this page handy.

how to stop thinking about work?

Are you on a vacation but can't stop thinking about your work? You might be a responsible person but that is not the reason you are thinking about it. Your routine is changed recently and you are in a new environment that is new to you. We are people of habits and actions.  Get away with the tools you use for your work or things that get your brain to work on. Your mobile, your laptop, camera or anything that trigger you to open it and check something or do something because you do not have anything to do. What could go wrong when you will be back on work. This thing is most common and reveals that you are scared of something or someone. Know that thing is important because you are giving it importance may be more than your health, your relationships and things that are actually important. Exercise is important but not always, drinking water is important but not always so work is important but not always. What you've chosen is to take a break, make sure that you are taking a br...

The Secret to Producing More Time in Your Life: 6 Core Time Management Principles

The Secret to Producing More Time in Your Life: 6 Core Time Management Principles Inspired by Dr. Sudhir Dixit’s "Time Management" | By Prem Kaithwas Some years back, I often said, “I wish I had more time .” I used to start my day full of energy, but by evening, I’d feel drained and incomplete — like I did a lot, but didn’t actually move forward. This feeling is common when you haven't mastered personal time management . Then I read Dr. Sudhir Dixit’s seminal book on Time Management. One line from it fundamentally changed how I looked at everything: “You can’t manage time. You can only manage yourself within time.” And it clicked. We all get the same 24 hours. The difference between those who create something meaningful and those who feel stuck isn’t a matter of time — it’s a matter of clarity and self-management . 1. Slow Down to Move Faster: The Power of Deep Work There was a phase where I’d open my laptop, start coding, reply to a few messages, then check something ra...