1

Hello guys I've been wondering if this could be feasible? I've been pondering over it for hours and I can't get my head wrapped around it!

Requirement:
I want to work on multiple git repositories in a project and push the code to corresponding repositories only.

Here is the overview:
I am working on multiple projects and these all projects use same custom library built by me. So, I created a git repository for the custom library and separate repositories for each project.

I created following Repositories:
lib: Custom Library
A: Project A
B: Project B

Setup for project A:

git init
git remote add origin 
git remote add library 
git pull origin master
git pull library master

Now after making a change in the project A code and when I try to push it by git push origin master then both the library code and project code are pushed to repository A.
But I want only project code should be pushed to repository A.

I have also tried doing it with branches and used following commands:

git checkout -b library
git pull library library

I also tried git pull library library:master

But getting the following error:

fatal: The remote end hung up unexpectedly
Lalit Arora
  • 301
  • 1
  • 3
  • 9
  • Have you considered using git submodules? (i.e. keeping your library in separate repo, and pulling it for each projects that uses it as a submodule) – keltar Mar 16 '14 at 13:28

3 Answers3

0

You need to keep the repositories separated by adding them as "git submodules." This allows you to keep multiple repositories in a project, and only the code from a specific project will get pushed to its respective remote.

The caveat here is that each submodule must be completely contained within a subdirectory. The files from the submodules cannot be mixed together.

BTownTKD
  • 7,911
  • 2
  • 31
  • 47
  • Thanks for your response. I want the two repo directories to be merged with each other. Like mine library has folder structure in it also and the projects are working like themes to the libraries placed in subfolders. – Lalit Arora Mar 16 '14 at 13:43
0

Dividing library code and project codes sounds fine, but pulling them into the same local repository cannot work. (In that case you have to decide, whether you want to check out a commit from the one or the other repository and you cannot work at both at the same time.)

You really need to keep them in separate local repositories. To combine them you can use submodules, subtrees, git-repo, gitslave or some custom or language specific way (mvn, rubygems, etc.) to refer to the library code.

Probably the best way is asking google for some suggestions.

michas
  • 25,361
  • 15
  • 76
  • 121
0

look into gitignore. I believe you should be able to make a gitignore for both the projects and list the files (files associated with the library) to ignore

tidepodz
  • 33
  • 2