Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to commit a git repository inside another git repository

I'm developing an application that uses git, so I need to test its integration with git. Inside my git repository, I need to have another repository (my_git_repo/tests/another_repo). How can I commit it without git submodules? (I don't want to have another remote repository (in github/bitbucket, etc) for just one file)

Any ideas?

like image 669
fj123x Avatar asked Jun 28 '15 12:06

fj123x


1 Answers

Submodules don't necessarily need to be cloned separately; you can publish a project and its submodules in a single repo. Just have a branch dedicated to the submodule contents in your main repo, then after cloning the main repo git clone -sb the submodule directly from there.

# setup your current repo this way:
( git init sub
  cd sub
  > file
  git add .
  git commit -m-
  git remote add origin ..
  git push -u origin master:sub/master
)

Setup in new clone:

git branch -t sub/master origin/sub/master
git clone -sb sub/master . sub 

and sub will have the most recent content.

git rev-parse :sub will show you what's committed for sub -- i.e. what should be checked out there -- when you don't just want the current branch tip.

You could hook up the git submodule command here, with a .gitmodules file and this and that, but it hardly seems worth it.

like image 120
jthill Avatar answered Sep 20 '22 12:09

jthill