When developing projects sometimes, it may only consist of the code that we created while in some cases it has codes that are generated by our IDE or our framework that aren’t actually needed. These files or folders sometimes also may generate errors when copied to other PC, so that’s why we need to ignore those unnecessary files or folders especially when pushing our code to GitHub
What is GitIgnore?
The first one is specifying by the specific filename. Here is an example, let’s say we want to ignore a file
Here is how your
.gitignore will look like.
The second one we can also write the name of the extension. For example, we are going to ignore all
.txt files, then write
There is also a method to ignore a whole folder. Let’s say we want to ignore folder named
test. Then we can just write
test/ in the file.
There are other ways to define the ignore files. But, as a starter, you will probably only use those 3 ways.
How to create .
- For readme in Github, we will only need a
README.mdfile. Let’s ignore if there is any file
- We also don’t need a folder
- Because there will be no Java files added to the repository, let’s ignore all of Java files (
You can check the rules based on the previous section to convert those rule into a
.gitignore file. You might get a similar file like this.
Save those file as
.gitignore file and put it into the root folder of the Git project. Now, if you try to add those files to the Git repository, it will be ignored. Because we already define the rule for files that going to be ignored by the Git.
One thing to note, if the files or folders already added to the Git project before we add it to the
.gitignore file, then those files or folders will still available in the Git project. Because we try to ignore those files or folders after we already add those to the Git tracking system.
What to GitIgnore
In most cases, we do ignore:
- IDE autogenerated files
- compiled versions of different files
- Some configuration files
Ignoring files and folders is important because not all of those files are needed when we try to move those project to other devices.
Thank you for reading. let me know on the comment section how helpful it was.
If you like the Article you can give it a clap 👏.
If you feel like you owe me