Reputation: 8627
I want to ignore bin and obj folders from my git repository. As I've found out, there is no easy way to do this in .gitignore. So, are there any other way? Using clean solution in Visual Studio?
Upvotes: 187
Views: 209483
Reputation: 455
In large projects, there are often more than one bin or object folder. So, you can use
**/bin/
**/obj/
to ignore all bin and object folders.
How to Ignore any 'bin' Directory on a Git Project?
Upvotes: 0
Reputation: 1
Look into .gitignore
file. If it doesn't exist, you can create it itself and you should add these :
Upvotes: 0
Reputation: 1907
After a recent update of Visual Studio 2019, the below option was not available. Alternatively, you can also copy the latest gitignore content from the below location. https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore
If you are using Visual Studio then there is a simple way to do this.
It will create a default .gitignore file, which will ignore most of the common folders & files that will be used by the framework/language.
Upvotes: 39
Reputation: 2400
Try adding the names of unwanted folders and git will never take those changes right from that root directory mentioned onward. This worked for me though to add these folder names into .gitignore
:
bin
obj
packages
Upvotes: 10
Reputation: 101
I have had some new developers check in their OBJ and Bin files to the repository. Even though I have the git ignore to exclude those files it would not work in my local repo.
I did the following to fix this
If you have other user specific files also in the repo ex: .suo in Visual studio you can add them to the gitignore file after doing the above.
I found this after wasting quiet a bit of time hope this helps some one in the same scenario.
Upvotes: 9
Reputation: 266
@Raphael Pinel is absolutely correct. .gitignore doesn't work if the files are already in the Git repository.
I'm using VS2019 and Azure DevOps as my Git repository. Here's how I fixed it.
In Visual Studio, add .gitignore file (if necessary) and push that file to the repository.
Team Explorer->Changes->Right Click
.gitignore->Stage.
Then commit staged, then sync.
Go to Azure DevOps website.
Delete bin/obj folders from Git repository.
In Visual Studio,
Team Explorer->Changes->"Undo Changes" to those folders.
Team Explorer->Synch->Pull to update local Git repository.
You can now build your project and Git will ignore the folders as specified in the .gitignore file.
Upvotes: 3
Reputation: 2766
In my case, bin and obj folders were nested under Project folder from the root .gitignore file, so I had to add it like below:
[PROJECT_FOLDER_NAME]/bin
[PROJECT_FOLDER_NAME]/obj
Replace PROJECT_FOLDER_NAME with your project folder name
Upvotes: 1
Reputation: 2800
If you have committed the bin and obj folders previously, adding them to .gitignore will not automatically delete them.
You need to commit deleting these folders with for example
git rm -rf obj
or git rm -rf yourProject/obj
then commit the deletion
Upvotes: 21
Reputation: 2602
simply making an entry in gitignore may not ignore files, you may need to commit it. I used the following method and worked for me
git rm -r --cached .
git add .
then
git commit -am "Remove ignored files"
However, this ignores my scripts folder which I included later into the repository.
Upvotes: 148
Reputation: 946
If you try through source tree and still the ignore files are not coming in , go to tools-->option->Git and then select location of the .gitignore
Upvotes: 0
Reputation: 17039
bin
and obj
folders in Windows ExplorerUpvotes: 7
Reputation: 54734
I'm not sure why this doesn't work for you. In case it helps, here's a typical .gitignore file from one of my Visual Studio/git projects:
*.suo
*.user
_ReSharper.*
bin
obj
packages
Upvotes: 254
Reputation: 32681
If you want to ignore bin and obj in ALL your projects then you can use (from gitignore man page)
Patterns read from the file specified by the configuration variable core.excludesfile.
core.excludesfile can be set in a config file which is ~/.gitconfig in Unix - I don't know where it is under Windows
Upvotes: 3