After adding files before a commit you may get the following message on a Windows OS

$ git add .
# It is perfectly safe to see a lot of messages here that read
# "warning: LF will be replaced by CRLF in file."

One way to deal with this is to ignore the warning and then make sure that the default setting for Windows OS is globally configured like so:

git config --global core.autocrlf true

And configured like the following on Linux and Mac OS:

git config --global core.autocrlf input

That may not be enough if you want to make sure everyones system work as you want without needlessly requiring developers to change their system settings.

Instead we can set rules for line endings via the .gitattributes file:

# Set the default behavior for all files.
* text=auto

# Normalized and converts to 
# native line endings on checkout.
*.c text
*.h text

# Convert to CRLF line endings on checkout (Windows OS).
*.aspx text eol=crlf

# Convert to LF line endings on checkout (Linux & MAC OS).
*.sh text eol=lf
*.php text eol=lf # Binary files. *.png binary *.jpg binary

After you have configured the core.autocrlf and committed a .gitattributes file, you will likely discover that Git wants to commit files that you have not modified. Git is able to change the line endings of every file for us.

So we should allow GIT to automatically configure our repository's line endings by first backing-up the files with Git, delete every file in the repository INDEX file, and then restore the index all at once.

1st - Save the current files in Git, so that none of the work you did is lost.

$ git add . -u
$ git commit -m "Saving files before refreshing line endings"

2nd - Remove the index and force Git to rescan the working directory.

 Linux / MAC OS:

$ rm .git/index

 Windows OS:

> del .git\index

3rd - Rewrite the Git index to pick up all the new line endings.

$ git reset

4th - Show the rewritten, normalized files.

$ git status

 5th - Add all your changed files back, and prepare them for a commit. This is your chance to inspect which files, if any, were unchanged.

$ git add -u

6th - Rewrite the .gitattributes file.

$ git add .gitattributes

7th - Commit the changes to your repository.

$ git commit -m "Normalize all the line endings"