Skip to content

Instantly share code, notes, and snippets.

@koemeet
Last active February 24, 2017 23:01
Show Gist options
  • Save koemeet/1c1e697dc4147f1b5c11a36c4a8e7639 to your computer and use it in GitHub Desktop.
Save koemeet/1c1e697dc4147f1b5c11a36c4a8e7639 to your computer and use it in GitHub Desktop.
Git submodules

Checklist, new feature:

  1. Go into main repo and verify you are on the master branch. Now run git pull && git submodule update.
Right now your main repo is up-to-date with the remote and all submodules are in a state the main repo rquires.
NOTE: Submodules are now probably in a detached state (detached HEAD), which is good. The main repo links to a specific commit (sha1 hash)
of the submodule, not an actual branch.
  1. If you want to make some updates IN the main repo, just create a new branch from master and do your magic!

I want to work on something in CommonSDK

  1. Create a new branch in CommonSDK and base it of your current HEAD (which is your working copy).
  2. Code your shit.
  3. Commit and push normally
NOTE: You need to watch out when working on your branch in CommonSDK, since the HEAD of this repository WILL change if you update
submodules in the main repo. Which can happen if you did some work in the main repo and then wanted to work on your CommonSDK changes again.

IMPORTANT: So always check your branch when you are working again on your CommonSDK changes!
  1. After you are finished with your CommonSDK changes, you can merge it into CommonSDK master (do this through github for easy merging).
  2. Now the CommonSDK master contains your new changes.
  3. To let everyone else taste your new changes in CommonSDK, remember to commit the new CommonSDK sha1 hash in the main repo. This will update the actual submodule.

I want to work on something in main repo which depends on the changes I just made in CommonSDK

Okay, so let's say you didnt merge your feature branch I mentioned earlier and are still working on it.

  1. In your main repo (Rust) create a new feature branch.
  2. Go into your submodule directory cd CommonSDK and make sure it is on the feature branch you made your changes in.
  3. Make some changes in the main repository and commit + push when you want to save it.

Lets say you are now done with your main repo changes + my submodule changes.

  1. FIRST make sure all submodules are merged into THEIR master branch. You may NEVER merge into main repo master when the submodules are still on their feature branch.
  2. Now commit + push the updated submodules again, so your feature branch on the main repo uses the submodules master branch.
  3. This is the time where you finally merge your feature branch of the main repo into master :D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment