Skip to content

Instantly share code, notes, and snippets.

@scmgopal
Created August 6, 2014 05:13
Show Gist options
  • Save scmgopal/3856ed2856934cdf9278 to your computer and use it in GitHub Desktop.
Save scmgopal/3856ed2856934cdf9278 to your computer and use it in GitHub Desktop.
Git Submodules CheatSheet
Recipes
Note: the [main]$ bits on each line represents your bash prompt. You should only type the stuff after the $.
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 .gitmodules -m "Added submodule as ./subm"
Fetch submodules after cloning a repository:
[~]$ git clone git://github.com/my/main.git ~/main
[~]$ cd ~/main/
[main]$ git submodule update --init
To get submodules automatically, you can use “git clone –recursive “
Pull upstream main repo changes and update submodule contents:
[main]$ git pull origin/master
[main]$ git submodule update
Pull upstream changes to the submodule:
[main]$ cd ./subm
[subm]$ git pull origin/master # or fetch then merge
[subm]$ cd ..
[main]$ git commit ./subm -m "Updated submodule reference"
Edit and commit files in your submodule:
[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"
Push your submodule changes to the submodule upstream:
[main]$ cd ./subm
[subm]$ git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment