No matter how I try, I can't get git
to track my file named foo/.git/bar
.
What I've tried
git add foo # no result
git add foo/.git # no result
git add foo/.git/bar # no result
git add --force foo/.git/bar # no result
cd foo && git add .git # no result
I understand that usually you wouldn't want to track such a file. I think that my use-case justifies it though.
My use case
I have a file named foo/.git/hooks/pre-push
in my git repository.
I will be using GNU stow to install this pre-push
file into a git repository somewhere else on my disk. To be clear, the folder foo
is not a git repository; it is just a folder named foo
that happens to contain a folder named .git
and a file .git/hooks/pre-push
. I want to track it.
How can this be accomplished?
CodePudding user response:
You can't.
Seriously, you can't. Git forbids you from having a file named .git
, in any upper or lower case mix, or any file with any component (part between slashes) whose name is .git
, in any upper or lower case mix.
Name the file something else.
CodePudding user response:
You can't as it was said. Just to extend the previous answer - if you want to do this for hooks what you can do is to have hooks simply in <repo>/hooks
and script or Makefile
target to setup developer environment that will put these in proper place. If you document that in README.md
or CONTRIBUTING.md
and tell people to run script as first thing it works pretty well and will also work for things beyond git
.
Also note it's not good idea to trust hooks on developer machine, even if developer forgets to install hooks that e.g. check code, add signature, etc. Remote CI or VCS server should catch these bad pull requests and reject them.