Easy way to pull latest of all git submodules

前端 未结 19 1582
谎友^
谎友^ 2020-11-22 05:20

We\'re using git submodules to manage a couple of large projects that have dependencies on many other libraries we\'ve developed. Each library is a separate repo brought int

相关标签:
19条回答
  • 2020-11-22 05:53

    If it's the first time you check-out a repo you need to use --init first:

    git submodule update --init --recursive
    

    For git 1.8.2 or above, the option --remote was added to support updating to latest tips of remote branches:

    git submodule update --recursive --remote
    

    This has the added benefit of respecting any "non default" branches specified in the .gitmodules or .git/config files (if you happen to have any, default is origin/master, in which case some of the other answers here would work as well).

    For git 1.7.3 or above you can use (but the below gotchas around what update does still apply):

    git submodule update --recursive
    

    or:

    git pull --recurse-submodules
    

    if you want to pull your submodules to latest commits instead of the current commit the repo points to.

    See git-submodule(1) for details

    0 讨论(0)
  • 2020-11-22 05:53

    I think you'll have to write a script to do this. To be honest, I might install python to do it so that you can use os.walk to cd to each directory and issue the appropriate commands. Using python or some other scripting language, other than batch, would allow you to easily add/remove subprojects with out having to modify the script.

    0 讨论(0)
  • 2020-11-22 05:55

    First time

    Clone and Init Submodule

    git clone git@github.com:speedovation/kiwi-resources.git resources
    git submodule init
    

    Rest

    During development just pull and update submodule

    git pull --recurse-submodules  && git submodule update --recursive
    

    Update Git submodule to latest commit on origin

    git submodule foreach git pull origin master
    

    Preferred way should be below

    git submodule update --remote --merge
    

    note: last two commands have same behaviour

    0 讨论(0)
  • 2020-11-22 05:55

    I often use this commands, it works so far.

    git pull
    git submodule foreach --recursive git checkout master
    git submodule foreach --recursive git pull
    

    Hope this faster.

    0 讨论(0)
  • 2020-11-22 05:56

    Note: This is from 2009 and may have been good then but there are better options now.

    We use this. It's called git-pup:

    #!/bin/bash
    # Exists to fully update the git repo that you are sitting in...
    
    git pull && git submodule init && git submodule update && git submodule status
    

    Just put it in a suitable bin directory (/usr/local/bin). If on Windows, you may need to modify the syntax to get it to work :)

    Update:

    In response to the comment by the original author about pulling in all of the HEADs of all of the submodules -- that is a good question.

    I am pretty sure that git does not have a command for this internally. In order to do so, you would need to identify what HEAD really is for a submodule. That could be as simple as saying master is the most up to date branch, etc...

    Following this, create a simple script that does the following:

    1. check git submodule status for "modified" repositories. The first character of the output lines indicates this. If a sub-repo is modified, you may NOT want to proceed.
    2. for each repo listed, cd into it's directory and run git checkout master && git pull. Check for errors.
    3. At the end, I suggest you print a display to the user to indicate the current status of the submodules -- perhaps prompt them to add all and commit?

    I'd like to mention that this style is not really what git submodules were designed for. Typically, you want to say "LibraryX" is at version "2.32" and will stay that way until I tell it to "upgrade".

    That is, in a sense, what you are doing with the described script, but just more automatically. Care is required!

    Update 2:

    If you are on a windows platform, you may want to look at using Python to implement the script as it is very capable in these areas. If you are on unix/linux, then I suggest just a bash script.

    Need any clarifications? Just post a comment.

    0 讨论(0)
  • 2020-11-22 05:57

    All you need to do now is a simple git checkout

    Just make sure to enable it via this global config: git config --global submodule.recurse true

    0 讨论(0)
提交回复
热议问题