当前位置: 动力学知识库 > 问答 > 编程问答 >

How do I force git to always use the master branch?

问题描述:

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 [email protected]:******.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?

网友答案:

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
分享给朋友:
您可能感兴趣的文章:
随机阅读: