The .gitignore
file is useful to specify what you want, and what you don’t want to be committed to Github.
In this post, I will show you how to create a Gitignore file in Visual Studio Code to make sure that you don’t commit stuff that you don’t want.
Why Use a Gitignore File?
it is recommended to create a .gitignore file before you commit anything to Github. When you commit and push something to Github, you might want to exclude some things from your commit: credentials (for security purposes), or other things like VS Code workspaces (for best practices).
Create Gitignore File in VS Code
It is recommended to create a .gitignore file before you commit anything to Github. When you commit and push something to Github, you might want to exclude some things from your commit: credentials (for security purposes), or other things like VS Code workspaces (for best practices).
To do so, you need to create a .gitignore
file with rules to what you want to be excluded from your commits. The .gitignore
file is a text file that tells Git which files or folders to ignore in a project.
To set-up a .gitignore
file using VSCode, go to File
> New File
, or click on the + file icon in the Explorer.
In this new file, add all the directories and files that you want to be ignored. Save the file as plain text file and name it .gitignore
within VS Code.
If you don’t know what to add in it, you can use my Gitignore template for Python. Just know that I have blocked common names I give to credential files, and the README.md
file because I don’t want changes to this file to impact my commit history. Just make sure that you update to file to your needs.
Now, save your .gitignore
file. Press CTRL + S
(on Windows), or Command + S
(on Mac), or go to File
> Save
.
Other Version Control with Git and Github Posts
Learn Git and Github (Complete Guide)
Get Started With Github
Basics of Version Control
How to Use Git and Github with VSCode
Conclusion
This is it, a simple Gitignore template to add to your repository. You can get the template on Github.
SEO Strategist at Tripadvisor, ex- Seek (Melbourne, Australia). Specialized in technical SEO. Writer in Python, Information Retrieval, SEO and machine learning. Guest author at SearchEngineJournal, SearchEngineLand and OnCrawl.