How to ignore files in git using .gitignore file


Git •gitignore file example

None of us will like to commit and add intermediate files to git repositories such as log and temp files, in order to not track specific files in your git repository you can make use of the gitignore.

.gitignore - Git will not track files that are specified in this file.

How to create a .gitignore file

Within your git project repository create a file named .gitignore

% touch .gitignore

Add file names/extenstions/regex to remove/ignore files

Any line that starts with as # hash or pound sign is a command and will be ignored!

Example: For Java Project:
# Compiled class file
*.class

# Log file
*.log

# Package Files
*.jar
*.war
*.ear
*.zip
*.tar.gz
Example:
% ls -a
.gitignore
2022070101_Local.log
release_1.2.0.jar
src
index.html

As you may see when I do a git status the log and jar files are not shown

% git status
.gitignore
src
index.html
-


Have Questions? Post them here!


Top Hashtags: