Ignoring Files

Some files might not be required to sent into the Staging Area or Local Repository. All such file names can be stored in a hidden file called .gitignore

Sree@SreeLaptop MINGW64 ~/MyWorkSpace (master)
$ git status
On branch master
nothing to commit, working tree clean

Sree@SreeLaptop MINGW64 ~/MyWorkSpace (master)
$ touch file{6..10}

Sree@SreeLaptop MINGW64 ~/MyWorkSpace (master)
$ git status
On branch master
Untracked files:
 (use "git add <file>..." to include in what will be committed)

file10
 file6
 file7
 file8
 file9

nothing added to commit but untracked files present (use "git add" to track)

Sree@SreeLaptop MINGW64 ~/MyWorkSpace (master)
$ cat >.gitignore
file7
file8

Sree@SreeLaptop MINGW64 ~/MyWorkSpace (master)

Here, we have added file7 and file8 to .gitignore file. Now if we perform git add . or git status the files file7 and file8 will not shown and not sent into staging area.

Sree@SreeLaptop MINGW64 ~/MyWorkSpace (master)
$ git status
On branch master
Untracked files:
 (use "git add <file>..." to include in what will be committed)

.gitignore
 file10
 file6
 file9

nothing added to commit but untracked files present (use "git add" to track)

Sree@SreeLaptop MINGW64 ~/MyWorkSpace (master)
$ git add .
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.

Sree@SreeLaptop MINGW64 ~/MyWorkSpace (master)
$ git status
On branch master
Changes to be committed:
 (use "git reset HEAD <file>..." to unstage)

 new file: .gitignore
 new file: file10
 new file: file6
 new file: file9

Sree@SreeLaptop MINGW64 ~/MyWorkSpace (master)
$

They will also not consider as untracked files. This way we can ignore any number of files.

Advertisements