2

We are have 2 rails projects for which /models are common for both of the projects and so we maintained a separate repo by using submodules concept.

Now in project1 I created a branch rails3_upgrade from master for my submodules i.e., in app/models.

how can I checkout to that branch in project2 models from master?

I tried get fetch --all and git remote -v and some other options but couldn't see the branch I created.

Googled but couldn't find. Can anyone tell me how can I do this?

Kranthi
  • 1,377
  • 1
  • 17
  • 34

1 Answers1

0

A branch created in a parent repo project1 won't be visible by other repos (submodules or project2)

You can create that branch in a submodule of Project1, and see it in the same submodule in project2

cd /path/to/project1/submodule1
git checkout -b newBranch
git push -u origin newBranch

cd /path/to/project2/submodule1
git fetch
git checkout newBranch --track origin/newBranch

As usual, is you make any modification in a submodule, don't forget to add and commit in the parent repo as well.

Creating a branch in a submodule does not mean the submodule will always checkout the latest of that branch though.
For that, see "Git submodules: Specify a branch/tag" I wrote before.
And for the submodule to update itself to the latest of that branch, you would need a

git submodule update --recursive
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • HI, I created a branch in my submodule only in Project1. I mean my app/models are submodules for both Project1 and Project2. So in Project1 I moved to app/models and from master I created a branch `new_branch`. After that I went to Project2 app/models and I tried to checkout to the branch which I created in Project1 app/models(`new_branch`). – Kranthi Dec 26 '15 at 05:00
  • @Thisisme OK, but did you push the branch you created in project1/app/models? Because app/model is its own git repo, and the same git repo in project2 will need to fetch that branch before being able to checkout it. – VonC Dec 26 '15 at 06:03
  • Yes I pushed and I can see the branch in the github repo as well. I have lot of commits in that branch as well. – Kranthi Dec 26 '15 at 06:40
  • @Thisisme So what is your question? What is the problem? Are you able or not to see that same branch and commits in your same submodule in project2? – VonC Dec 26 '15 at 06:54
  • Yes, am not able to see the branch in project2 – Kranthi Dec 26 '15 at 11:05
  • @This project2 would not see a branch created in another repo. Only Project2/app/model would see that branch – VonC Dec 26 '15 at 12:28