{"id":2377,"date":"2018-08-19T18:20:46","date_gmt":"2018-08-19T23:20:46","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=2377"},"modified":"2018-08-19T18:20:46","modified_gmt":"2018-08-19T23:20:46","slug":"git-how-to-create-and-use-a-gitignore-file-on-windows","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2018\/08\/19\/git-how-to-create-and-use-a-gitignore-file-on-windows\/","title":{"rendered":"Git: How to create and use a .gitignore file on Windows"},"content":{"rendered":"<p>If you have a project that you have git enabled, but you don&#8217;t want git to track all of the files in the project folder (perhaps because you don&#8217;t want all files to be uploaded to github), you can tell Git to ignore certain files, file types, or sub-directories by creating a &#8220;.gitignore&#8221; file in your git repository.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2382\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/08\/gitignore.png\" alt=\"\" width=\"210\" height=\"137\" \/><\/p>\n<p>To set up a .gitignore file on a Windows machine, in your command window cd to the git directory and type the command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">run dir &gt; .gitignore<\/pre>\n<p>This outputs the entire directory listing to a file named .gitignore in your git directory.<\/p>\n<p>To edit the .gitignore file, open it in Notepad++ and replace the directory listing with a single line that contains the file types you want git to ignore. For example, if you want git to ignore .pyc files:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">*.pyc<\/pre>\n<p>When you run the git status command in your project folder, Git will read every line of the .gitignore file, where each line is a condition that git should ignore. The types of conditions that can be set in the .gitignore file are:<\/p>\n<ul>\n<li>File types<\/li>\n<li>individual file names<\/li>\n<li>specific directories<\/li>\n<\/ul>\n<p>Here is a table that shows how to implement each of these condition types:<\/p>\n<table id=\"lang-compare-table\">\n<tbody>\n<tr>\n<td><strong>File types<\/strong><\/td>\n<td>*.pyc<\/td>\n<\/tr>\n<tr>\n<td><strong>individual file names<\/strong><\/td>\n<td>thisfile.txt<\/td>\n<\/tr>\n<tr>\n<td><strong>specific directories<\/strong><\/td>\n<td>directory_name\/<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Notes:<\/p>\n<ul>\n<li>Notice that * can used as a wildcard (meaning anytime this pattern is found).<\/li>\n<li>Also note that for specific directories, all that is needed is to append the directory name with a forward slash.<\/li>\n<li>Pound signs &#8216;#&#8217; can be used as comment lines<\/li>\n<\/ul>\n<p>Here is an example of a <a href=\"https:\/\/github.com\/github\/gitignore\/blob\/master\/Grails.gitignore\">real<\/a> .gitignore file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\"># .gitignore for Grails 1.2 and 1.3\r\n# Although this should work for most versions of grails, it is\r\n# suggested that you use the \"grails integrate-with --git\" command\r\n# to generate your .gitignore file.\r\n\r\n# web application files\r\n\/web-app\/WEB-INF\/classes\r\n\r\n# default HSQL database files for production mode\r\n\/prodDb.*\r\n\r\n# general HSQL database files\r\n*Db.properties\r\n*Db.script\r\n\r\n# logs\r\n\/stacktrace.log\r\n\/test\/reports\r\n\/logs\r\n\r\n# project release file\r\n\/*.war\r\n\r\n# plugin release files\r\n\/*.zip\r\n\/plugin.xml\r\n\r\n# older plugin install locations\r\n\/plugins\r\n\/web-app\/plugins\r\n\r\n# \"temporary\" build files\r\n\/target<\/pre>\n<p>&nbsp;<\/p>\n<p>There are many other real .gitignore files that can be used as examples here:<br \/>\n<a href=\"https:\/\/github.com\/github\/gitignore\">https:\/\/github.com\/github\/gitignore<\/a><\/p>\n<p>For more information about gitignore, see:<br \/>\n<a href=\"https:\/\/help.github.com\/articles\/ignoring-files\/\">https:\/\/help.github.com\/articles\/ignoring-files\/<\/a><br \/>\n<a href=\"https:\/\/git-scm.com\/docs\/gitignore\">https:\/\/git-scm.com\/docs\/gitignore<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have a project that you have git enabled, but you don&#8217;t want git to track all of the files in the project folder (perhaps because you don&#8217;t want all files to be uploaded to github), you can tell Git to ignore certain files, file types, or sub-directories by creating a &#8220;.gitignore&#8221; file in &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2018\/08\/19\/git-how-to-create-and-use-a-gitignore-file-on-windows\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Git: How to create and use a .gitignore file on Windows<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[78],"tags":[79],"class_list":["post-2377","post","type-post","status-publish","format-standard","hentry","category-technologies-and-tools","tag-git"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/2377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=2377"}],"version-history":[{"count":6,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/2377\/revisions"}],"predecessor-version":[{"id":2384,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/2377\/revisions\/2384"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=2377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=2377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=2377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}