简体   繁体   中英

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 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM