Home » Git Tutorial » Writing a .gitignore

Writing a .gitignore


()

What is .gitignore?

If we add up .gitignore file into our repository, Git actually determines what files or pattern of the files that should not be included in the repository.

Suppose, if we want to add a java project, running a maven build for the project creates a /target folder wherein all the created JARs will be stored.
We don’t want to clutter our repository space with un-necessary JAR files.
Hence we tend to ignore the entire folder by adding the pattern to .gitignore.

Same applies for the project file for other projects.

Though there is a list of well know .gitignore files available of every kind of project that we generally work on, ranging from java to python etc.

Below is the .gitignore file created for maven project.
Though we have flexibility to choose a predefined .gitingore file,

You still can create a custom .gitignore file.

1.) Ignoring a specific file

You may tend to ignore a specific file by providing its relative complete path with extension.

Suppose, if we don’t want a CSV file called as “dummy.csv” which exists in output folder.
We can write the path in the output folder as

/output/dummy.csv

2.) Ignoring a folder and its content

If we want to ignore a folder and its content, provide the folder name followed by *

Suppose, if we don’t want to add any file present inside the output folder of the repository.
We can simply write it by

/output/*


3.) Ignoring a file extension

Suppose, if we want to ignore certain type of file to be present in the repository, we can do so by specifying the extension of the file.

READ  Installing Git on Windows

E.g
*.com, *.zip, *.JAR etc.

Conclusion
The above tutorial helps you Understand, how can you create a pre-existing .gitignore file or how you can manually create your own version of .gitignore to avoid adding a file to file pattern into the repository.

References
https://www.atlassian.com/git/tutorials/saving-changes/gitignore
https://coursework.vschool.io/create-a-gitignore/

 

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote Count

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Array Interview Questions
Graph Interview Questions
LinkedList Interview Questions
String Interview Questions
Tree Interview Questions