Search code examples
gitgithubgitignore

.gitignore - ignoring image files not working


I have this .gitignore file:

.DS_Store
node_modules
/dist
screen

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# Vue Browser Extension Output
*.pem
*.pub
*.zip
/artifacts

I'm trying to add a rule that will tell to git to ignore the .jpeg or .jpg and .code-workspace files, but the added rules added are ignored when I push the repository online and these files are anyway copied. Is this syntax correct?

# Ignoring psd and image files
*.jpg
*.psd
# Ignoring VS workspace files
*.code-workspace

Solution

  • The syntax in .gitignore looks good.

    What about your repository: are the.jpg and .jepg files pushed to the repository? If the files stay already in the repository (git push already executed), you must untrack this file. Then after push the file Git will tracked this added files and any skipping matching rules will be skipped.

    With following command you can removes the file from the repository without physically deleting:

    git rm --cache folder/to/the/imagefiles

    After committing that change, all files will be removed from the repository, and ignoring should work properly.

    git rm documentation.