I have a php project that uses composer for package management. One of the packages is another project belonging to the same repo. I have a need to commit my entire vendor folder, but I want to ignore the .git folder in the sub-project so that it doesn't get treated like a submodule.
So far I have had no success. Things I've already tried:
vendor/.git
vendor/**/.git/
google search
stack overflow search
Here's what the sub-project folder looks like in GitLab. Instead of the files, it's just some kind of reference.
To not treat sub folder as a submodule, delete the
.git
folder. So that you won't see a folder with@number
in the website. If you want to update the submodule. You can create a script like the following written inShell
update.sh
update.bat
I believe this is the best way to avoid
@number
in GitLabYou can refer my GitHub repository created for answering this question.
It looks like git automatically ignores .git folders in subfolders of root repository.
For me this looks like a design error:
If you load a second project from the same repository as dependency, this project should be moved to a different repository.
And inside the vendor Directory place another .gitignore file with
You can use git hooks to achieve what you want. Thinking out of the box, you could use pre-commit hook to rename 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:
2) Create post-commit file under .git/hooks/ also with contents:
3) Change a file in your repo and finally:
The entire
vendor
folder should be ignored, not just the.git
sub-directories. Which packages are used are stored incomposer.json
andcomposer.lock
which are what you check into version control.See: https://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md
If you want to create a reusable package as part of your project, you have two options:
A) Use Composer to handle another repo
Add to
composer.json
...B) Use a 2nd packages directory
You can create a
packages
directory and add it to your autoload paths. This will let you use a single Git repo for all the code (if you want to use two repos, you can use a Git submodule)Add to
composer.json
...Documentation is your friend
Git Documentation said that:
So you may try the following code to ignore
.git
folder in subdirectories:I also wonder why are you going to ignore the folder instead of deleting it.