The most obvious way would be to add these to src/.gitignore :
obj/ bin/
This ignores any paths that are in a directory call obj, or a directory called bin from the src directory downwards.
Something like src/*/obj/ in a top-level .gitignore might not work if you have a jagged project hierarchy with some obj and bin directories futher down the tree.
Here's quick test shell script showing the ignore rule in action:
#!/bin/sh mkdir src mkdir tools mkdir src/project1 mkdir src/project2 mkdir tools/tool1 mkdir src/project1/bin mkdir src/project1/obj mkdir src/project2/bin mkdir src/project2/obj mkdir tools/tool1/bin touch testfile touch src/testfile touch tools/testfile touch src/project1/testfile touch src/project2/testfile touch tools/tool1/testfile touch src/project1/bin/testfile touch src/project1/obj/testfile touch src/project2/bin/testfile touch src/project2/obj/testfile touch tools/tool1/bin/testfile git init add_empty() { touch "$1" && git add "$1"; } add_empty dummy add_empty src/dummy add_empty tools/dummy add_empty src/project1/dummy add_empty src/project2/dummy add_empty tools/tool1/dummy git status printf 'obj/\nbin/\n' >src/.gitignore && git add src/.gitignore git status
The untracked file section of the first status is:
# Untracked files: # (use "git add <file>..." to include in what will be committed) # # src/project1/bin/ # src/project1/obj/ # src/project1/testfile # src/project2/bin/ # src/project2/obj/ # src/project2/testfile # src/testfile # testfile # tools/testfile # tools/tool1/bin/ # tools/tool1/testfile
And after adding the .gitignore file:
# Untracked files: # (use "git add <file>..." to include in what will be committed) # # src/project1/testfile # src/project2/testfile # src/testfile # testfile # tools/testfile # tools/tool1/bin/ # tools/tool1/testfile
As a test to prove that git isn't ignoring files called obj and bin but is ignoring obj and bin directories further down the hierarchy after running this script:
#!/bin/sh mkdir src/project3 touch src/project3/testfile && git add src/project3/testfile touch src/project3/obj touch src/project3/bin mkdir src/subdir mkdir src/subdir/proj touch src/subdir/proj/testfile && git add src/subdir/proj/testfile mkdir src/subdir/proj/obj mkdir src/subdir/proj/bin touch src/subdir/proj/obj/testfile touch src/subdir/proj/bin/testfile
The new untracked files are:
# Untracked files: # (use "git add <file>..." to include in what will be committed) # # src/project1/testfile # src/project2/testfile # src/project3/bin # src/project3/obj # src/testfile # testfile # tools/testfile # tools/tool1/bin/ # tools/tool1/testfile