lint-staged: what the purpose of 'git add' command



Recently I started to introduce lint-staged into my Frontend build tool chain. And when I checked the document about it, I always find it works as following:

"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
"lint-staged": {
    "src/**/*.{js,jsx,ts,tsx,json,css}": [
      "prettier --write",
      "eslint --fix src/",
      "tslint --fix --project .",
      "git add"

and you can find more similar usage in the link:

My confusing point is the last command git add, what’s the purpose of that?

My understand is lint-staged only validate the code in staged area after git add and before git commit. So can’t understand why we need to add one more git add again.


It’s using husky to hooks some actions before your commit. See at:

lint-staged just changes your code and make it linting (It runs before commit by husky). After changed, you need add it again to update git index. And your changes will be effect in your commit.

Answered By – Chien Nguyen

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More