Github Submodule Setup

If you need a refresher on using git in general, see “The Basics” section below.

Think of a submodule as a github repo inside another github repo (I know, woah).

  • Each class will have a repo for assignments.

  • Each student/group will create a totally separate repo for their work

  • This should not live in the main work repo

  • Each student/group will clone the main work repo, and then link their own repo as a submodule

  • Each student/group will get rid of their local copy of the main repo

  • Each student/group will work on their assignment in the repo created in step 1

Ok, but what about more instructions with examples you say?

  1. Create & clone your own repo

    Do all your work in this repo.

    $ git clone https://github.com/jonalf/work-test.git
    Cloning into 'work-test'...
    remote: Counting objects: 3, done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), done.
    Checking connectivity... done.
    
  2. Clone the main repo
    $ git clone https://github.com/mks65/euler.git
    Cloning into 'euler'...
    remote: Counting objects: 14, done.
    remote: Compressing objects: 100% (9/9), done.
    remote: Total 14 (delta 5), reused 9 (delta 3), pack-reused 0
    Unpacking objects: 100% (14/14), done.
    Checking connectivity... done.
    
  3. Change into the correct directory and add your repo as a submodule

    Submodule adding is done by: git submodule add -b <BRANCH> <URL TO YOUR REPOSITORY> <required submodule directory name>

    $ cd euler/
    socrates: euler dw$ cd 04/
    socrates: euler/04 dw$ git submodule add -b main https://github.com/jonalf/work-test.git dyrland-weaverJon
    Cloning into '04/dyrland-weaverJon'...
    remote: Counting objects: 3, done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), done.
    Checking connectivity... done.
    
  4. Commit and push changes
    $ git pull
    Already up-to-date.
    socrates:~/Desktop/git_demo/euler/04 dw$ git commit -a -m "added dw submodule"
    [master f25eeda] added dw submodule
     2 files changed, 4 insertions(+)
     create mode 100644 .gitmodules
     create mode 160000 randomizer/6/jonalf_dw
    socrates:~/Desktop/git_demo/euler/04 dw$ git push
    Counting objects: 5, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (5/5), done.
    Writing objects: 100% (5/5), 626 bytes | 0 bytes/s, done.
    Total 5 (delta 0), reused 0 (delta 0)
    To https://github.com/mks65/euler.git
    11dc0c6..f25eeda  master -> master
    

    You do not have to pull first, but it is a good idea in case anyone has pushed before you have a chance to.

  5. Remove the main repo and go about your business
    $ cd ../../
    $ rm -rf euler/