Site icon Dreniq News

Learn about the .gitignore file and how to use it most effectively

Learn about the .gitignore file and how to use it most effectively

Generating a sitemap can be a time-consuming and difficult task, but with the .gitignore file you can make this process much easier. This article will help you learn about the .gitignore file and how to use it most effectively

What is .gitignore file?

 .gitignore file is a file specified by Git. Its task is to list the files that you do not want to put in Git or simply understand that Git will ignore those files.

How does it work?

It can be understood simply that git will ignore a file or a set of files in our project when committing and pushing to the repository. Eg: The files that need to be ignored here can be automatically generated IDE files, files to run applications on personal computers, personal files that need to be secured.…

Git manages the files that we want to “ignore” with the .gitignore file located in the project root directory.

When adding a new file to git, git will check the list of files to ignore in the .gitignore file and not add them to git. That’s just a necessary condition, a sufficient condition that the files are no longer in the git cache, then it will be ignored by git, but if the files are in the git cache, .gitignore will be useless.

How to use .gitignore file most effectively?

Using this ignore feature of Git is quite simple. As a first step, you need to create a file in the root directory of your project and name it .gitignore, for example:

touch .gitignore

Then open the file with the text editor.

Apply the following 2 rules:

For example:

# ignore ALL .log files

*.log

# ignore ALL files in ANY directory named temp

temp/

So, the current state of all .log files and everything in the temp directories will not be considered by Git.

Syntax rules in .gitignore file

In order for Gitignore to correctly identify the files you need to ignore, it requires that you enter the correct syntax when entering the syntax.

– An empty line can be used as a delimiter for readability.

– The sign # at the beginning of each line means that line to comment.

– The sign ” / ” when placed at the end of the new syntax is considered a Gitignore file, otherwise it will just be considered a normal file or symbol.

– The sign ” !” means a negative, meaning that if a file contains it, it will not be ignored.

– The ” * ” matches everything except ” / “, ” ? ” and any one character except ” / ” and ” [ ] “. With this ” * ” can be understood as the name of the file, the name of the folder. Quite useful when you want to ignore an entire file type (.xml, template/.xlsx, … ).

– Use ** to ignore directories that do not need to be specified. For example, /Lab will ignore all files or folders named Lab anywhere in the project scope.

For which objects should the .gitignore file be used?

In actual fact, choosing which file to utilize Gitignore for will depend on the individual’s needs. Here are some of the most popular versions:

Conclusion

Through the above article, we have given you a comprehensive overview of how to use the .gitignore file effectively and some notes when using it. If there are any difficulties during the implementation, do not hesitate to contact us immediately or leave a comment below so that we can assist you as soon as possible. Thanks for reading!

Exit mobile version