Git and Git Subrepo

Hi,

I am newbie to Git and starting to learn it. I have been using SVN for quite a long time. I want to simulate following.

  1. I have a main repo in folder ‘main’. I can pull, commit and push in this folder.
  2. I have one folder in ‘main’ named ‘srepo’. I am able to clone a subrepo in this folder ‘srepo’

I added a few files to subrepo ‘srepo’ locally and want to push to upstream subrepo. when I execute command ‘git subrepo add FileName.txt’  then it gives me error git-subrepo: ‘add’ is not a command. See ‘git subrepo help’.

When I execute command ’ git subrepo commit’ it gives me following message:-

git-subrepo: Command ‘commit’ requires arg ‘subdir’.
  Usage: git subrepo commit <subdir> [<subrepo-ref>]
  Add subrepo branch to current history as a single commit.
  This command is generally used after a hand-merge. You have done a subrepo</font> <font color="#0000FF">  branch and merged (rebased) it with the upstream. This command takes the
  HEAD of that branch, puts its content into the subrepo subdir and adds a new
  commit for it to the top of your mainline history.

  This command requires that the upstream HEAD be in the subrepo/&lt;subdir&gt;
  branch history. That way the same branch can push upstream. Use the
  --force option to commit anyway.

  The commit command accepts the --force option.

After adding subdir name with commit command it says “git-subrepo: Can’t commit: ‘subrepo/origin’ doesn’t contain upstream HEAD.”

Please let me know how fix this?

The main repo in folder main would be a standard repository. The folder main/srepo would be what Git calls a submodule. But because submodule working trees within a superproject are tied to a specific commit, you wouldn’t typically develop directly within main/srepo but you would have a srepo project somewhere else that you would develop in and then update the commit that main has to that known-good version.

If you don’t want to have that extra formalism of the submodule, then I would recommend just treating main/srepo as a component that you work on logically separately but isn’t phyisically separated. You could do this by having just one Git repository and working on separate branches that only touch things inside main/srepo or outside main/srepo but not both.

I hope that helps!

Hey, https://github.com/ingydotnet/git-subrepo is a thing, and it’s not (really) submodules. It’s also tricky to figure out how to use.

Starting out:
git subrepo clone # clone existing repo. Use --force to overwrite into an already existing folder
or:
git subrepo init # make a repo out of a previously existing and possibly not empty folder. Remote repo url can be supplied later during push, saved with --save

Daily usage:

git subrepo pull # see git subrepo help for a list of all the steps this command does. It’s complicated.
git subrepo push # push changes. But always pull first (says subrepo docs…)

3 Likes