KcFnMi KcFnMi - 4 months ago 27
Git Question

Push sub-repo content together (not using git submodules)

Inside a main repo, there is another repo (which might have been downloaded from github, i.e.), I call this a sub-repo.

I don't want to use git submodules feature.

The sub-repo might be commited and pushed to his own remote eventually. But I would like to carry on work in the main repo, ignoring that folder (sub-repo) actually is a git repo. But I would like to track the sub-repo content from the main-repo (I was studying the consequences here).

I was successful in this endeavor until the point where I pushed main-repo commits, when I noticed the sub-repo content wasn't pushed together. Even though I added it when committing.


git ls-files
, I see the folder (sub-repo) is there, but files aren't listed, so I'm not sure the sub-repo content is acctualy being tracked by main-repo.

git ls-tree --full-tree -r HEAD
, I see the sub-repo being called a
, instead of a
as is the case for other files of the main-repo.

Is it possible to push the sub-repo content together?


I tried and files in sub-repo can be pushed together with main-repo. The following steps can be refered:

  1. Git bash in local main-repo
  2. Use git clone <URL for sub-repo> to clone the sub-repo under main-repo
  3. Use git status, you will find a untracked folder sub-repo, then use git add sub-repo/ and git commit to track
  4. Add a file, such as new.txt in /main-repo/sub-repo directory
  5. Use git add sub-repo/new.txt and git commit (note: it’s run in the /main-repo directory)
  6. Use git push to push to remote main-repo, and you can find the file new.txt also there. Also you can use git ls-files to find the file

Note: You may have noticed that the mode is 160000 if we use git add sub-repo and git commit, and mode 100644 if we use git add sub-repo/ and git commit. 1600000 is Gitlink, it means you record a commit as a directory rather than a subdirectory or a file, somewhat like submodules. 100644 means regular non-executable file. So you can treat sub-repo as a folder.