Commit 80f2666077035629058ac24b78fb91c52f7b7ff3

Authored by Lars Tiede
1 parent 7d188012

instructions with branch to avoid destruction of master

Showing 1 changed file with 17 additions and 5 deletions   Show diff stats
@@ -14,7 +14,13 @@ Now reset your working copy of this repository to the commit right before we add @@ -14,7 +14,13 @@ Now reset your working copy of this repository to the commit right before we add
14 git reset --hard 375c69b8e9ffb36b79c0d7cc0121d622c5b169aa 14 git reset --hard 375c69b8e9ffb36b79c0d7cc0121d622c5b169aa
15 ``` 15 ```
16 16
17 -Okay, now there shouldn't be any my\_lib. Let's add it as a submodule: 17 +Okay, now there shouldn't be any my\_lib. Let's make ourselves a branch in order to not mess up the master branch:
  18 +
  19 +```bash
  20 +git checkout -b YOU_CHOOSE
  21 +```
  22 +
  23 +Now add my\_lib as a submodule:
18 24
19 ```bash 25 ```bash
20 git submodule add git@source.uit.no:lars.tiede/lunsjdemo_my_lib.git my_lib 26 git submodule add git@source.uit.no:lars.tiede/lunsjdemo_my_lib.git my_lib
@@ -47,7 +53,7 @@ Now we will deliberately do something awful and commit parent *and push it to or @@ -47,7 +53,7 @@ Now we will deliberately do something awful and commit parent *and push it to or
47 ```bash 53 ```bash
48 git add my_lib 54 git add my_lib
49 git commit -m "new version of my_lib" 55 git commit -m "new version of my_lib"
50 -git push 56 +git push --set-upstream origin YOUR_BRANCH_NAME
51 ``` 57 ```
52 58
53 Now what do you think will happen when somebody wants to clone that? Let's try: 59 Now what do you think will happen when somebody wants to clone that? Let's try:
@@ -56,7 +62,7 @@ Now what do you think will happen when somebody wants to clone that? Let's try: @@ -56,7 +62,7 @@ Now what do you think will happen when somebody wants to clone that? Let's try:
56 cd .. 62 cd ..
57 mkdir temp_clone 63 mkdir temp_clone
58 cd temp_clone 64 cd temp_clone
59 -git clone --recursive git@source.uit.no:lars.tiede/lunsjdemo_parent_with_submodule.git . 65 +git clone -b YOUR_BRANCH_NAME --recursive git@source.uit.no:lars.tiede/lunsjdemo_parent_with_submodule.git .
60 ``` 66 ```
61 67
62 Notice the '--recursive' option? You have to do that in order to not only clone parent, but also all submodules of parent. Yes, you and your users will forget about that constantly. This is the biggest headache with submodules. But there's another. Check this at the end of the output: 68 Notice the '--recursive' option? You have to do that in order to not only clone parent, but also all submodules of parent. Yes, you and your users will forget about that constantly. This is the biggest headache with submodules. But there's another. Check this at the end of the output:
@@ -66,7 +72,7 @@ fatal: reference is not a tree: 5870fc7691231edf23517055b09768e00e123bf7 @@ -66,7 +72,7 @@ fatal: reference is not a tree: 5870fc7691231edf23517055b09768e00e123bf7
66 Unable to checkout '5870fc7691231edf23517055b09768e00e123bf7' in submodule path 'my_lib' 72 Unable to checkout '5870fc7691231edf23517055b09768e00e123bf7' in submodule path 'my_lib'
67 ``` 73 ```
68 74
69 -(Your hash might differ). Git couldn't clone the referenced commit of my\_lib *because it did not find it*. And that is because we did not push (i.e. publish) our changes to my\_lib before we published our changes to parent. **Always push changes to children before you push parent** in order to make sure that the published parent always points to commits of children that are already published.. 75 +(Your hash will differ). Git couldn't clone the referenced commit of my\_lib *because it did not find it*. And that is because we did not push (i.e. publish) our changes to my\_lib before we published our changes to parent. **Always push children before you push parent** in order to make sure that the published parent always points to commits of children that are already published..
70 76
71 So here's how we fix this: push the child, then update the submodules in our temporary working copy. Pushing the child is easy, here's how you pull and update submodules in temp\_clone: 77 So here's how we fix this: push the child, then update the submodules in our temporary working copy. Pushing the child is easy, here's how you pull and update submodules in temp\_clone:
72 78
@@ -76,4 +82,10 @@ git submodule update --init --recursive @@ -76,4 +82,10 @@ git submodule update --init --recursive
76 82
77 That command clones submodules if they haven't been cloned yet, and it pulls a new commit when parent's reference has changed. So that command is what you also have to do after every 'git pull' of parent. This is the second big headache with submodules: you have to remember to update the submodules after 'git pull'. 83 That command clones submodules if they haven't been cloned yet, and it pulls a new commit when parent's reference has changed. So that command is what you also have to do after every 'git pull' of parent. This is the second big headache with submodules: you have to remember to update the submodules after 'git pull'.
78 84
79 -But that's basically it, now you know how submodules work. You can delete temp\_clone now. 85 +But that's basically it, now you know how submodules work. Delete your branch now so that there is no pollution here:
  86 +
  87 +```bash
  88 +git push origin --delete YOUR_BRANCH_NAME
  89 +```
  90 +
  91 +Finally, you can delete temp\_clone.