Set files not managed by Git --.gitignore

Use the ".gitignore" file to set files that are not managed by Git. Create the file with the touch command. If you write it in ".gitignore", it will not be ready for commit with git add command.

touch .gitignore

.gitignore can be placed anywhere in the repository, but it is recommended to manage it at the top of the repository.

Absolute path

If you write it with an absolute path, it will be written from the root of the Git repository.

"/ Foo" is no longer managed.

/ foo

"/ Foo / bar" is no longer managed.

/ foo / bar

Relative path

If you write it with a relative path, the files contained somewhere in the root directory of the Git repository will not be managed.

In the following cases, all the files "foo.txt" will not be managed.

foo.txt

You can use wildcards, so you can say that you don't just manage the logs.

* .log

Manage again in the one that was removed

Use "!" To manage again among the unmanaged ones. Where do you use this?

Manage directories

The only stumbling block to writing .gitignore is that you can't just manage directories. This is a Git specification.

If you want to manage a directory, first create a file called ".gitkeep" in the directory. This is a customary name and is the recommended name.

If you want to manage a directory called foo, create ".gitkeep" in the "foo" directory.

Then use wildcards to state that you don't manage all the files in the foo directory first.

foo / *

Since .gitkeep is also out of control, use "!" To describe that it will be managed again.

! foo / .gitkeep

The following is a summary.

foo / *
! foo / .gitkeep

Now you can manage your foo directory in your Git repository.

Associated Information