OK, here is a GIT quiz. If you have a GIT repo folder called Parent1Repo and inside that you have 2 folders, Child1Repo and Child2. Both Child1Repo and Child2 have some files in it. Whether accidentally or intentionally, you make Child1Repo a GIT repo on its own. If you clone Parent1Repo what will you get in the cloned repo. Will you get everything from Child1Repo or just the file contents not the repo (.git folder). To see the result, here is the script that does what exactly described earlier.
# Setting up ParentGITRepo & Child1Repo and Child2 $ cd ~ $ mkdir ParentGITRepo $ cd ParentGITRepo/ $ git init . $ mkdir Child1Repo $ mkdir Child2 $ cd Child1Repo/ $ git init . $ echo "Child1RepoFile" > Child1RepoFile.txt $ git add . $ git commit -a -m "Adding Child1Repo content" $ cd ../Child2/ $ echo "Child2 file content" > Child2File.txt $ cd .. $ echo "Parentfile" > ParentFile.txt $ git add . $ git commit -a -m "Adding Parent content" # Now verify ParentGITRepo & Child1Repo working independently $ cd ~/ParentGITRepo/ $ git log $ cd ~/ParentGITRepo/Child1Repo/ $ git log # Now try cloning ParentGITRepo & verify the contents inside it $ cd ~ $ git clone ParentGITRepo/ $ cd ParentGITRepoClone/ $ ls -a ./ ../ .git/ Child1Repo/ Child2/ ParentFile.txt $ cd Child1Repo/ $ ls -a ./ ../
So, the answer is you don’t get nothing from Child1Repo. Why? Because, GIT ignores sub folders which are GIT repos on its own. The right way to do this kind of setup is through git sub modules. The worse thing is, even if you remove everything from Child1Repo and try to add back in inside the ParentGITRepo, it won’t let you do until you remove it from the parent GIT repo’s cache (git rm –cached Child1Repo). I had this issue discussed in GIT discussion group recently, here is the link if you are interested to know more.
OK, what if I don’t want Child1Repo as a sub module, I just want it as main GIT repo just the way it is right now. Yes, you can do that. But, if you clone, pull, or push, you gotto do it like this.
$cd ~/ParentGITRepoClone/Child1Repo $git clone ~/ParentGITRepo/Child1Repo/ .
I am going to let the readers decide if its a GIT bug or an unsupported feature
. Bottom line is, if you have a GIT repo and you have another GIT repo in it’s folder hierarchy, you make sure you keep it in the right state.
Recent Comments