Thursday, May 13, 2021

GIT Basics - Ignoring unwanted File and Folders - gitignore

Ignoring unwanted File and Folders - git ignore


git status

Untracked files:

.DB_Store

my git is clean, however i have this OS file under untracked file list

When we commit every time we need to make sure we are not adding this file to git repo.

This is error prone. git provides a solution for that --> .gitignore file


ls -al  --> list all files

mate .ignore

format for this file is --> one expression per line and below are the three types

Specific file: Myfile.txt

File pattern: *.ext

Folders : my-folder/


Now if you list all files u can still see all files with . and .. and .DB_Store

ls -al

git status

Untracked files:

.gitignore

So let's add this .gitignore file

git add .gitignore

git status

Changes to be committed:

new file: .gitignore

git commit

"adding .gitignore file to exclude unwanted files

git status

nothing to commit, working directory clean

2. Let's think we have a log file in our directory. Not just that , any log file which may come in future

*.log --> entry to .gitignore  file

3. if logs are going for a "log" directory

log/  --> entry to .gitignore  file


No comments:

Post a Comment