3

I have some Xcode project I'm trying to clone from GitHub using git, and it has external submodules as well. Whenever I try to clone, it keeps putting these external submodules as well as every folder in the project on "(no branch)" instead of master. This is what I'm doing in Terminal:

git clone git@github.com:******.git
cd ******
git submodule update --init
cd External/******
git submodule update --init
cd External/******
git submodule update --init

If I cd into any folder and do git branch, I get this:

git branch
* (no branch)
master

Is there a way I can force git clone to use the master branch everywhere?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
sudo
  • 5,604
  • 5
  • 40
  • 78
  • `git submodule update --init --recursive` should be enough – Luke Hutton Jul 25 '13 at 03:15
  • Do the submodules have different `master` branches than the parent repo? If you switch them to `master`, will the submodules still work with the parent repository, or will their code be incompatible? –  Jul 25 '13 at 03:34
  • If I switch them to master, it works, but I have to go through and manually do it to each folder, which is annoying. In fact, if I don't switch them to master, I get compile errors where it can't find files that exist. – sudo Jul 25 '13 at 05:02

1 Answers1

16

This requires git 1.8.2 or later (March 2013)

It depends on how those submodules are declared in the .gitmodules:

See "git submodule tracking latest"

That would allow you to follow the master branch.
Update your current .gitmodules with a:

git config -f .gitmodules submodule.<path>.branch master
git submodule update --remote --recursive

Note that the submodule still won't be on any branch. Simply their SHA1 would be the one of origin/master.
You would still need to checkout master for each of them.

git submodule foreach --recursive git checkout master
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250