0

I work a lot with sourcetree and when you stage there it does not include the embedded repositories. I don't know how they do it but that's what I would like to achieve via the command line. I read through the documentation of git add here (https://git-scm.com/docs/git-add) but couldn't find anything that accomplishes this. I could implement this with a bash script but I was wondering maybe I was missing something and there is a simpler way to do this?

By the way, I wouldn't want to solve this with a command that requires typing the exact name of the embedded repositories because I have many such manifest repositories and I am looking for a generic solution.

EDIT: Here is how to reproduce it yourself: by creating any git repo and within it create another git repo. Go to the parent repo and do git add . and you will see that git gives you the following message:

enter image description here

+++++++++++++++++++

The background:

I have a repository that contains several other embedded repositories. I manage all the embedded repos using a manifest file (a text file listing each repository and its associated commit and brach) and when I want to sync them I simply checkout the relevant branches and commits based on the manifest file using a bash script I wrote. I am building an app that implements a multi-repo management solution that combines features from submodules and google's repo with the addition of a graphical user interface. That is why I am purposely not using submodules here.

Eyal Gerber
  • 1,026
  • 10
  • 27
  • 1
    If you don't use submodules, doesn't "all changes and files except submodules" just mean "all changes and files"? – mkrieger1 Dec 19 '21 at 11:39
  • @mkrieger1 from what I tested that is not the case. For example, if I do `git add .` or `git add -A` it will stage also the embedded repositories. – Eyal Gerber Dec 19 '21 at 12:04
  • 2
    Yes, but if they are not submodules, a solution that will add everything "except submodules" will not help you. – mkrieger1 Dec 19 '21 at 12:58
  • 2
    Does this answer your question? [Git ignore .git folder](https://stackoverflow.com/questions/34618950/git-ignore-git-folder) - If not, please show a [mre]. – mkrieger1 Dec 19 '21 at 12:59
  • @mkrieger1 regarding your second comment, you are right. I modified the title of the question. Regarding your last comment, I added a reproducible example to the question. The link you provided as a possible answer does provide a generic solution with post and pre commit scripts however, I feel it is not as elegant and simple as the answer provided by jthill below. He provided a solution with just one pre commit script. – Eyal Gerber Dec 20 '21 at 13:32
  • UPDATE: I found another answer that seems to be much simpler and cleaner. Simply to add the relevant folders to gitignore. This seems rather simple and it worked perfectly for me. Since I already had the subrepos tracked I had to remove them from being tracked and only then update the gitignore. I learned about this solution from here: https://stackoverflow.com/a/57085288/4441211 – Eyal Gerber Jan 20 '22 at 09:27

1 Answers1

2

I manage all the embedded repos using a manifest file (a text file listing each repository and its associated commit nd brach) and when I want to sync them I simply checkout the relevant branches and commits based on the manifest file using bash script I have.

You do understand that your bash script implements submodules, right? .gitmodules is a text file listing tracked histories, the origin repositories used to fetch them and the various options you like to use when working with them, and git adding a nested repository lists it in the Git manifest aka index.

If you're wedded to the way you're doing things, I'd suggest a pre-commit hook that scrapes any added gitlinks out of the index and updates-and-re-adds your manifest file, then maybe pops a note if it made any changes. This would be like a five-liner (just like a large majority of git submodule commands can be implemented as five-liners).

git ls-files -cs | grep ^16

will list all your tracked histories. Assuming to keep things simple that you keep your manifest file keyed in that format the update is a straight sort -t$'\t' -usk2,2 | join pipe.

jthill
  • 55,082
  • 5
  • 77
  • 137
  • This is a good solution since it is only one script that can be implemented as a pre-commit script. I will actually use it as a bash script that is used by my app that is creating and managing all my manifest repositories. I was thinking of implementing something like this but I was hoping there was a simpler way like with a special flag that I might have missed for `git add`. – Eyal Gerber Dec 20 '21 at 13:30
  • I don't see the advantage to duplicating Git's submodules rather than just using them. For projects small enough that you don't have to worry about onboarding you don't need any of it, just nested repos and knowing where your source came from is enough, the submodule helper and your system alike add complexity but no value, but once having a README starts saving you time getting others up to speed just use Git's submodule helper, it helps. – jthill Dec 20 '21 at 16:15
  • I respect what you are saying but I believe whether or not to use submodules is a larger debate. You can browse online and you will find online multiple forum discussions and blog posts on the pros and cons of submodules and google's repo tool. So while something might seem intuitive and simple to you, there are many who don't share the same thought :) – Eyal Gerber Dec 20 '21 at 16:31