cd /path/to/your/parent/repogit add path/to/your/submodulegit commit -m "Make submodule tracking a branch"
该子模块的后续更新必须使用--remote选项:
# update your submodule# --remote will also fetch and ensure that# the latest commit from the branch is usedgit submodule update --remote
# to avoid fetching usegit submodule update --remote --no-fetch
[alias]
######################## Submodules aliases#######################
# git sm-trackbranch: places all submodules on their respective branch specified in .gitmodules# This works if submodules are configured to track a branch, i.e if .gitmodules looks like:# [submodule "my-submodule"]# path = my-submodule# url = git@wherever.you.like/my-submodule.git# branch = my-branchsm-trackbranch = "! git submodule foreach -q --recursive 'branch=\"$(git config -f $toplevel/.gitmodules submodule.$name.branch)\"; git checkout $branch'"
# sm-pullrebase:# - pull --rebase on the master repo# - sm-trackbranch on every submodule# - pull --rebase on each submodule## Important note:# - have a clean master repo and subrepos before doing this!# - this is *not* equivalent to getting the last committed# master repo + its submodules: if some submodules are tracking branches# that have evolved since the last commit in the master repo,# they will be using those more recent commits!## (Note: On the contrary, git submodule update will stick# to the last committed SHA1 in the master repo)sm-pullrebase = "! git pull --rebase; git submodule update; git sm-trackbranch ; git submodule foreach 'git pull --rebase' "
# git sm-diff will diff the master repo *and* its submodulessm-diff = "! git diff && git submodule foreach 'git diff' "
# git sm-push will ask to push also submodulessm-push = push --recurse-submodules=on-demand
# git alias: list all aliases# useful in order to learn git syntaxalias = "!git config -l | grep alias | cut -c 7-"