Git Submodule command line sample

Recipes



    Note: the [main]$ bits on each line represents your bash prompt. You should only type the stuff after the $.
    1. Set up the submodule for the first time:
      [~]$  cd ~/main/
      [main]$  git submodule add git://github.com/my/submodule.git ./subm
      [main]$  git submodule update --init
      [main]$  git commit ./submodule -m "Added submodule as ./subm"
      
    2. Fetch submodules after cloning a repository:
      [~]$  git clone git://github.com/my/main.git ~/main
      [~]$  cd ~/main/
      [main]$  git submodule update --init
      
    3. Pull upstream main repo changes and update submodule contents:
      [main]$  git pull origin/master
      [main]$  git submodule update
      

    4. Pull upstream changes to the submodule:
    5. [main]$ cd./subm
      [subm]$ git pull origin/master        # or fetch then merge
      [subm]$ cd ..
      [main]$ git commit ./subm -m "Updated submodule reference"
      
    6. Edit and commit files in your submodule:
    7. [main]$  cd ./subm
      [subm]$  edit whatever.rb
      [subm]$  git commit whatever.rb -m "Updated whatever.rb"
      [subm]$  cd ..
      [main]$  git commit ./subm -m "Updated submodule reference"
      
    8. Push your submodule changes to the submodule upstream:
      [main]$  cd ./subm
      [subm]$  git push origin master
      
    9. Edit and commit files in your submodule
      $ cd your_submodule
      $ git checkout master
      <hack,edit>
      $ git commit -a -m "commit in submodule"
      $ git push
      $ cd ..
      $ git add your_submodule
      $ git commit -m "Updated submodule"
      

    留言

    這個網誌中的熱門文章

    ng2-smart-table 自定 column 資料

    C# Create An AutoComplete TextBox on WinForm

    查出哪個程式佔用 port 443