Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Using 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.

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

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

like image 925
KcFnMi Avatar asked Apr 28 '26 14:04

KcFnMi


1 Answers

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 is 100644 if we use git add sub-repo/ and git commit. 1600000 is Gitlink, it means you record a commit as a directory entry 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.

like image 169
Marina Liu Avatar answered May 01 '26 18:05

Marina Liu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!