I'm looking to create a .gitignore
file so certain files are do not get checked in to the repository. Does anyone have a guide on how and where to place this file? I have tried placing it in my working directory, ran git status and it is still picking up on the files I would like it to ignore.
I used this .gitignore
file I have found:
###################
# compiled source #
###################
*.com
*.class
*.dll
*.exe
*.pdb
*.dll.config
*.cache
*.suo
# Include dlls if they’re in the NuGet packages directory
!/packages/*/lib/*.dll
# Include dlls if they're in the CommonReferences directory
!*CommonReferences/*.dll
####################
# VS Upgrade stuff #
####################
UpgradeLog.XML
_UpgradeReport_Files/
###############
# Directories #
###############
bin/
obj/
TestResults/
###################
# Web publish log #
###################
*.Publish.xml
#############
# Resharper #
#############
/_ReSharper.*
*.ReSharper.*
############
# Packages #
############
# it’s better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
######################
# Logs and databases #
######################
*.log
*.sqlite
# OS generated files #
######################
.DS_Store?
ehthumbs.db
Icon?
Thumbs.db
You can create a . gitignore file in your repository's root directory to tell Git which files and directories to ignore when you make a commit. To share the ignore rules with other users who clone the repository, commit the . gitignore file in to your repository.
The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked. To stop tracking a file that is currently tracked, use git rm --cached.
gitignore should list the names or name-patterns of files that will be found in work-trees when working with your project, but that should not be committed to the project. In other words, it's not OS-specific, it's project-specific.
Placement of .gitignore depends if the files need to be ignored for just one repo or for all your repos. For one repo, place it in the root of your repo.
When you create a .gitignore file in an existing repo, or add files that were already in the repo, you have to make sure to remove the to-be-ignored files from the repo.
If you have a test.dll in the root, you have to do
git rm --cached test.dll
Now if you have a lot of files, like you said you can opt for the following option, remove everything from the cache, add it all back (the files in .gitignore will not be added) and commit everything again.
git rm -r --cached .
git add .
git commit -m "Start using .gitignore"
You have to add .gitignore
to the index before Git sees it. I.e., git add .gitignore
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With