Home > Software engineering >  Git checkout command overrides folders in .gitignore
Git checkout command overrides folders in .gitignore

Time:01-01

I'm working on this project under a tight schedule and I have this error, below is a summary of how I got this error.

  • Working on Weatherme for viewing the weather location (my first actual implementation of APIs with Vue.js 3)
  • Got tired of the old design and decided to move to TailwindCSS - my definition of a sweet library
  • Made a new branch migrate-design-tailwind to push to GitHub
  • I recently switch to the default branch (main) to get a copy of a piece of functionality.

The issue is when I check the package.json file in Visual Studio Code, it tells me certain packages are not available (not a problem right)

So I re-installed the packages and the errors go away. That was the first time. The second time the same dependencies weren't found. This is a sample of my .gitignore

# Node modules
/node_modules

# Project logs
/logs

# Other stuff, don't look here
todo.txt
tailwind.full.config.js

The checkout command I used is git checkout main

Code can be found here

CodePudding user response:

After you check out your code you need to do npm install, more or less every time. If you make sure your package-lock.json is checked in and restored when you check out your code, you'll install a reproducible set of packages.

CodePudding user response:

I found a library called husky, which can be found on npm or yarn which helps in the process of adding git hooks to a project.

Installation is pretty simple for npm users - $ npx husky-init && npm install Installation differs for yarn users

$ npx husky-init && yarn              # Yarn 1
$ yarn dlx husky-init --yarn2 && yarn # Yarn 2

I could get the checkout hook in my project easily using the command

$ npx husky add .husky/post-checkout "npm install"

I found all the hooks for git at this site

Happy New Year ✌

  • Related