Search code examples
gitatlassian-sourcetree

How to stage (git add) all changes and new files except embedded repositories?


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.


Solution

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