Create GitIgnore File
What is GitIgnore File?
GitIgnore is a file that tells Git which files or folders to ignore in a project. It is used to avoid committing unwanted files to a Git repository such as temporary files created by the editor vi or temporary build files. It is also used to avoid committing sensitive information such as passwords or API keys to a public repository.
How to Create GitIgnore File?
Creating getting a file is quite simple you just need to create a normal file you can use touch dot Gitignore or you can create it from VS code or any editor you are using or you can directly create from your explorer. Just create a file where you don't need to give the name to the file just use dot get ignore
How to Create GitIgnore File?
Creating getting a file is quite simple you just need to create a normal file you can use touch dot Gitignore or you can create it from VS code or any editor you are using or you can directly create from your explorer. Just create a file where you don't need to give the name to the file just use dot get ignore
How to use GitIgnore File to Ignore Files?
To Use Gitignore File just paste the file downloaded file to the root of the github repo, no need to configure anything. Just paste the file and you are good to go. If the code is push first you can clear the cache of the git by using git rm -r --cached . and then push the code again.
How to use GitIgnore File to Ignore Folders?
There is simple rules to ignoring folders in Gitignore file. Just add the folder name in the gitignore file and you are good to go. If you want to ignore the folder and all the subfolders then you can use /foldername/ and if you want to ignore the folder and all the subfolders and files then you can use /foldername/*. for example if you want to ignore the node_modules folder and all the subfolders and files then you can use /node_modules/* and if you want to ignore the node_modules folder and all the subfolders then you can use /node_modules/
How to use GitIgnore File to Ignore Files and Folders?
To ignore files and folders in Gitignore file you can use the same rules as we have used to ignore the folders. Just add the file name or folder name in the gitignore file and you are good to go. If you want to ignore the folder and all the subfolders then you can use /foldername/ and if you want to ignore the folder and all the subfolders and files then you can use /foldername/*. for example if you want to ignore the node_modules folder and all the subfolders and files then you can use /node_modules/* and if you want to ignore the node_modules folder and all the subfolders then you can use /node_modules/
Why GitIgnore File not Working?
There are many reasons why Gitignore file is not working. The most common reason is that you have not added the file to the root of the github repo. If you have added the file to the root of the github repo then you can clear the cache of the git by using git rm -r --cached . and then push the code again. Or there are some rules for gitignore file to work properly. You can check the rules here.
Rules for GitIgnore File
There are some rules for gitignore file to work properly. You can check the rules here. To Avoid the Gitignore file not working you can follow the rules. Rule 1 The File that you already pushed on github you can't ignore it. Rule 2 Folder name should be in the gitignore file. Rule 3 If you want to ignore the folder and all the subfolders then you can use /foldername/ and if you want to ignore the folder and all the subfolders and files then you can use /foldername/*. for example if you want to ignore the node_modules folder and all the subfolders and files then you can use /node_modules/* and if you want to ignore the node_modules folder and all the subfolders then you can use /node_modules/ Rule 4 If you want to ignore the file then you can use the file name in the gitignore file. Rule 5 If you want to ignore the file and all the subfolders then you can use /filename/ and if you want to ignore the file and all the subfolders and files then you can use /filename/*. for example if you want to ignore the package-lock.json file and all the subfolders and files then you can use /package-lock.json/* and if you want to ignore the package-lock.json file and all the subfolders then you can use /package-lock.json/