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

Is heaven actually a higher planet?

Exoplanet Existence of heaven is a lot like existence of God. You never saw him but you know in your heart that the God does exist and he is guiding you at times and he is the reason you are alive. I do not know whether heaven exists or not, neither I've seen it with my eyes. There are different believes among different people, religion and texts but they are all based on something that has been passed on by generations or found in religious texts. Heaven is a place where people want to go but they do not know where it is, neither Google map can locate it. Heaven is a place that is good, rich and has got everything you will ever need. This place would be pleasing for somebody who is not rich does not have enough in this life that is the reason he or she is eager to know whether there is a heaven or not. To have hope to go there by their good deeds if that's the way. Real or just a possibility? There are so many planets in our galaxy and there are so many galaxies in our univers...