gitgithub

How to use gitignore command in git


I'm working first time on git. I have pushed my branch on github and it pushed all the library and documents into the github. Now what can I do and how can I use gitignore command to avoid the same mistake again.


Solution

  • So based on what you said, these files are libraries/documentation you don't want to delete but also don't want to push to github. Let say you have your project in folder your_project and a doc directory: your_project/doc.

    1. Remove it from the project directory (without actually deleting it): git rm --cached doc/*
    2. If you don't already have a .gitignore, you can make one right inside of your project folder: project/.gitignore.
    3. Put doc/* in the .gitignore
    4. Stage the file to commit: git add project/.gitignore
    5. Commit: git commit -m "message".
    6. Push your change to github.