Jessica
Jessica

Reputation: 2415

How to put Git repository inside another repository?

So I cloned this code from repository A, and made a subfolder B inside the code. All my work is done in the subfolder, and I want to put the subfolder under version control, but I never want to push changes in B to repository A. In fact I don't think I even have push access to repository A. How can I put subfolder B into repository B?

I heard about submodules but I'm getting errors when I try to use them: (I'm in subfolder B right now)

user@host:~/code$ git init
Initialized empty Git repository in /pathtosubfolder/code/.git/

user@host:~/code$ git submodule add .
repo URL: '.' must be absolute or begin with ./|../
user@host:~/code$ git submodule add ./
fatal: could not create work tree dir ''.: No such file or directory
Clone of '/pathtosubfolder/code/' into submodule path '' failed
user@host:~/code$ git submodule status
user@host:~/code$ rm -rf .git
user@host:~/code$ git submodule init
You need to run this command from the toplevel of the working tree.

Thanks!

Upvotes: 2

Views: 2119

Answers (1)

BaBL86
BaBL86

Reputation: 2622

  1. Create B repository with your code
  2. In your A project folder do:

    git submodule add git://repo-b-path.git codes

  3. You must work with "submodule" command in your A repo

Upvotes: 4

Related Questions