1

I have 3 repos I used to track each of them.

enter image description here

Now, I want to track the parent project directory instead.

I've created a new repo in Bitbucket.

Go to my 2018/

clone
add url 
commit
push

This is all I see in my Bitbucket source

enter image description here

How do I adjust my git so it will track the sub folders?


I've tried

git submodule add

⚡️  2018  git submodule add external/
repo URL: 'external/' must be absolute or begin with ./|../
⚡️  2018  git submodule add internal/
repo URL: 'internal/' must be absolute or begin with ./|../
⚡️  2018  git submodule add api/     
repo URL: 'api/' must be absolute or begin with ./|../
⚡️  2018  

Update

  cd internal/
  git submodule add git@bitbucket.org:bhengdev/2018.git
  cd .. 
  cd external/
  git submodule add git@bitbucket.org:bhengdev/2018.git
  cd .. 
  cd api/
  git submodule add git@bitbucket.org:bhengdev/2018.git
  cd .. 

  git status 



  ⚡️  2018  git status
  On branch master
  Your branch is up-to-date with 'origin/master'.
  Changes not staged for commit:
    (use "git add <file>..." to update what will be committed)
    (use "git checkout -- <file>..." to discard changes in working directory)
    (commit or discard the untracked or modified content in submodules)

          modified:   api (modified content, untracked content)
          modified:   external (modified content, untracked content)
          modified:   internal (modified content)

  no changes added to commit (use "git add" and/or "git commit -a")
  ⚡️  2018
Community
  • 1
  • 1
code-8
  • 54,650
  • 106
  • 352
  • 604
  • Do you still want the three folders to be their own repos, or would you be okay with a single repo for everything? – Tom Nov 23 '17 at 20:30
  • I don't know what is the best way yet. This is the first time I want to do this. Now, I want the 3 folders to still in it owned repo. – code-8 Nov 23 '17 at 20:34
  • 1. the `git submodule add` should be run in the top most, main project. api, external and internal can be your original git repository clone upfront. 2. Do not `git add` these folders to the main project, instead just run the `git submodule add` command from the main project, it will create there a .gitmodules file! – kisp Nov 24 '17 at 07:09

1 Answers1

1

What about using git submodules?

You could add each of your subfolders or subprojects as a submodule to the main project.

You can add your subprojects with the git submodule add <repositoryURI> [<path>] command.

Later you can edit the .gitmodules file which submodule is located where.

Git submodules

For configuration see the examples at the bottom of the following page:

Git submodules configuration examples

When cloning or pulling a repository containing submodules
the submodules will not be checked out by default;
You can instruct clone to recurse into submodules. The init
and update subcommands of git submodule will maintain 
submodules checked out and at an appropriate revision in
your working tree. 
Alternatively you can set submodule.recurse to have checkout 
recursing into submodules.

You can also run a command manually on each:

git submodule foreach 'git pull'

or

git submodule update --init

kisp
  • 6,402
  • 3
  • 21
  • 19
  • It does not seem to work. I updated my post with the result of that. Do u have any other suggetion ? – code-8 Nov 23 '17 at 16:46
  • Yes, I also updated the command. Check the git help submodule for help. You can specify remote url's for every sub-module repository as well. The submodule command gives you an interface for updating your subfolder's content, or displaying status of them. – kisp Nov 23 '17 at 17:01
  • I still have issue. `(modified content, untracked content)` do you know how to fix it ? – code-8 Nov 23 '17 at 20:26
  • Maybe this is your answer : https://stackoverflow.com/questions/4161022/git-how-to-track-untracked-content#4162672 – kisp Nov 23 '17 at 21:26
  • That accepted answer on that link is very confusing! :( – code-8 Nov 23 '17 at 21:36
  • It is about that you should not add those directories to the main project with git add. If you did this, you need to start over. git submodule is a different approach than git add and when you start to use it in the wrong order it will result some untracked info. – kisp Nov 24 '17 at 07:13
  • So. How do I fix it ? How do use it the right way ? – code-8 Nov 24 '17 at 13:38
  • What would people do if they in my position now ? – code-8 Nov 24 '17 at 13:38
  • Remove it, with `git rm` from the superproject, then add it again with `git submodule add` (from the superproject). - you can find this in the linked answer's "Turn It into a Proper Submodule" section. – kisp Nov 24 '17 at 18:51