Is it possible to add a sub folder with a .git folder to a repo, without Git treating it like a submodule? I've tried different methods to ignore that .git folder, but nothing this far has worked.
I have tried in /.gitignore:
/vendor/**/.git/
..and in /vendor/.gitignore:
.git/
The .git folder I want to ignore is in /vendor/foo/bar/.
You can do this by directly adding some (any) internal content first. Git detects submodules by encountering the .git
entry when searching a newly-encountered directory, but if you give it an actual path to look for inside that directory it doesn't search.
So
git add path/to/some/submodule/file # bypass initial search that detects .git
git add path/to/some/submodule # now git's index has it as ordinary dir
You can use git hooks to achieve what you want. Thinking out of the box, you could create a pre-commit hook that renames the .git directory of your included project, eg. to ".git2", add all files in the latter project except the ".git2" directory, commit all, push it and finally use post-commit hook to rename ".git2" folder back to ".git" in your module.
1) Create pre-commit file under .git/hooks/ of your root repo with contents:
#!/bin/sh
mv "vendor/foo/bar/.git" "vendor/foo/bar/.git2"
git rm --cached vendor/foo/bar
git add vendor/foo/bar/*
git reset vendor/foo/bar/.git2
2) Create post-commit file under .git/hooks/ also with contents:
#!/bin/sh
mv "vendor/foo/bar/.git2" "vendor/foo/bar/.git"
3) Change a file in your repo and finally:
git commit -a -m "Commit msg"
git push
My Original answer
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