Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to make outer repository and embedded repository work as common/standalone repository?

I have a big project(let's say A repo), and it there one child folder which is come from B repo. I would meet warning like below when I commit from A repo

warning: adding embedded git repository: extractor/annotator-server hint: You've added another git repository inside your current repository. hint: Clones of the outer repository will not contain the contents of hint: the embedded repository and will not know how to obtain it. hint: If you meant to add a submodule, use: hint: hint:   git submodule add <url> extractor/annotator-server hint: hint: If you added this path by mistake, you can remove it from the hint: index with: hint: hint:   git rm --cached extractor/annotator-server hint: hint: See "git help submodule" for more information. 

I have seen git-submodule and git-subtree:

Maintaining Git repo inside another git repo

https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree

But I don't like them , because they need extra config.


What I want is , for example:

structure like:

A/ --- a.py  --- B/ --- B/b.py 

When I change B/b.py .

  1. If I am on path A/ , git add can detect B/b.py changed, git push only commit that to A repo.

    git add .   (would add changes under A/  ) git push   (would push changes under A/  ) git pull   (would pull changes under A/  ) git clone XXX:A  (would clone all files under A/ ,    A/B/ is just looks like plain folder with all files, not a repo ) 
  2. If I am on path A/B/ , git add only add B/b.py changes to B repo, and git push only commit that to B repo.

    git add .   (would add changes under B/ , but not add changes to A repo) git push   (would push changes under B/ , but not push changes to A repo) git pull   (would clone changes under B/ ,  ) git clone XXX:B  (would clone all files under B/  ) 
  3. Once I want to snyc A and B in another machine, just do

    git clone A rm -rf A/B/ git clone B ./B git add . && git commit 'sync with B' 

In another word, A and B act as a standalone repo.

But the truth is , A repo treat B repo as submodule:

A repo https://github.com/eromoe/test

B repo https://github.com/eromoe/test2


How do I force A repo track all files under A/ , and B repo track all files under A/B/ ? I want A and B act as a self-contain repo , without any other config.

like image 930
Mithril Avatar asked Oct 30 '17 04:10

Mithril


People also ask

Can you have two repositories?

That's why it is necessary to use multiple Git repositories. Another big benefit that comes with using multiple repositories is that it can make teamwork efficient without the need to depend on each other. This means that they can work independently and work faster than ever.

How do I create a common repository on GitHub?

In the command line, navigate to the directory where you would like to create a local clone of your new project. To create a repository for your project, use the gh repo create subcommand. When prompted, select Create a new repository on GitHub from scratch and enter the name of your new project.


Video Answer


2 Answers

You can use below commands to add files from test2 repo to test repo as below:

# In local test repo rm -rf test2 git clone https://github.com/eromoe/test2 git add test2/ git commit -am 'add files from test2 repo to test repo' git push 

Note:

You should use git add test2/ (with slash, not git add test2).

git add test2/ will treat test2 folder and it's files as ordinary folder and file for test repo (create mode 100644).

git add test2 will treat test2 folder as a submodule for test repo (create mode 160000).

like image 163
Marina Liu Avatar answered Sep 21 '22 02:09

Marina Liu


Probably, git reminded the repository. It helped for me:

     git rm --cached your_folder_with_repo     git commit -m "remove cached repo"     git add your_folder_with_repo/     git commit -m "Add folder"     git push 
like image 36
rost shan Avatar answered Sep 24 '22 02:09

rost shan