Time Saving Yaml Tricks

DRY: Don’t Repeat Yourself If you have a section that’s being repeated multiple times, you can create an anchor and then reference it. You use &name to create an anchor, and then *name to reference it. One example of it is defining environment variables for different services in docker-compose.yaml. env_vars: &env ENVIRONMENT: production LOGLEVEL: info AWS_REGION_NAME: us-east-1 services: api: environment: *env ... ... backend: ... ... environment: *env Reading environment variables While yaml doesn’t read environment variables, but if you pair it with parser, you can read the environment variables. The syntax depends on the parser you are using. The most common places, where I have a need for reading environment variables (or context variables) in yaml file is, cicd pipeline namely github action or circleci and docker-compose. ...

February 12, 2025 · 2 min · 293 words · Mohit Sharma

All the ways to `git add`

I always get confused with, should I run git add ., or should I run git add --all, or should I run git add -A? Given all these commands, do a similar thing, confusion is bound to happen. Thankfully, it’s not just me. So I decided to take a deep dive into add command of git, to end this confusion once and for all. What does add even do? The add command adds your changes to staging area. Staging area is a buffer zone where you place your files before committing them. This buffer zone allows you to be selective with your commits, there are some files that you want to commit now and some files that you want to commit later. Staging area is also known as index. ...

October 24, 2024 · 3 min · 560 words · Mohit Sharma

How to parse json in terminal using jq

A practical tutorial on jq So here’s the problem statement: Find the repository on github in which you have made most number of commits? And you need to do this on terminal (no python) Ofcourse, one can use python to find the answer, and it might be probably easy for you, if you have been using python for last many years. But let’s see if I can do this in terminal with jq and while doing so, let’s learn about it. ...

April 1, 2024 · 4 min · 787 words · Mohit Sharma

How to `find` files in terminal?

Manager: Hey, I need your help, I have couple of images that are taking a lot of space on my PC, I want to delete them. How can I do that? Developer: Well that should be simple. Here, you go. This looks for all files with .png extension in the current directory and its subdirectories (using -R flag), then pipes those file names to rm command to delete them. ls -R | grep ".png$" | xargs rm Manager: Nice, but wait. This will delete all the png files in the current directory and its subdirectories. I only want to delete in specific directories. ...

February 21, 2024 · 2 min · 363 words · Mohit Sharma