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.

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...

I have feelings for her but she has a boyfriend

Disappointed man Address your feelings, analyse why you have this feelings? Ofcourse because you are human and humans do have feelings.  When it comes to others there is always a good reason why you feel someway about someone? How you've been treated by the other person everytime you had an encounter with that person? Why you feel there is a connection? Yes! Pheromones there genetic make up and other aspects that make us feel attracted towards someone is there but you will be attracted once, twice or as long as the person is around. You will eventually forget about the person in the long run. But if that's not happening then there must be a good reason why you can't let the person go. What is it that is missing and why do you want to be with this person? Okay! What is the ultimate thing you want with this person? What kind of relationship you want with this person? Give yourself time. Life won't be and it was never about you and your own self. The people in your life ma...