When working with Git, you might have files (like .class, .log, or temp files) that you don’t want to upload to GitLab or GitHub. That’s where .gitignore comes in handy.
What is .gitignore?
The .gitignore file tells Git which files or folders to ignore (not track).
How to Set Up .gitignore
- Create a .gitignore file In your project root folder (same place where .git is), create a new file:
.gitignore
Add file patterns to ignore
Example .gitignore:
*.class # ignore all Java compiled class files
*.log # ignore all log files
/temp/ # ignore temp folder
Remove already tracked files (if needed)
If .class files are already tracked, Git won't ignore them just by adding to .gitignore.
Run this to remove them from tracking:
git rm --cached *.class
Commit and push
git add .gitignore
git commit -m "Added .gitignore file"
git push
Done! Git will now ignore those files in future commits.
referel links :
1 :Link: https://git-scm.com/docs/gitignore
2 : Link: https://github.com/github/gitignore
Top comments (0)