I was going to write some longer comments about submodules, and I can still do if needed. Instead I’ve got 2 links that might be helpful, the Git Book chaper on submodules, and this blog post which goes in to the internals a bit (it is quite old though). Now onto the brain dump…
They key thing to take away is that there is a difference between the source URL to the submodule and the stored commit hash of the submodule. The commit hash is stored in the Git history, it does not care what the source URL is. Git is distributed after all!
The URL is stored in the .gitmodules file, and should always be https://github.com/monome/libavr32.git unless you know what you are doing. Don’t commit a change that modifies that. The URL in .gitmodules is just the initial checkout URL. If you want to change the origin URL for the submodule for a local copy just:
cd libavr32
git remote set-url origin git@github.com:samdoshi/libavr32.git
# also a good idea to set an upstream remote
git remote add upstream git@github.com:monome/libavr32.git
Now you can push, pull and fetch to your own GitHub account. (There are other ways to do this too… I think.) To revert to the .gitmodules URL, do a git submodule sync.
If you want to update the commit that the parent repo points to, change the checked out version of libavr32 and commit the libavr32 directory, e.g. to update it to upstream/master (this is assuming that libavr32 is clean and that you haven’t made any commits to it).
cd libavr32
git checkout master # checkout local master branch
git fetch upstream
git rebase upstream/master # rebase local master onto upstream/master
cd ..
git add libavr32
git commit -m "updated libavr32 to master"
git push # now go to GitHub and open a PR
You could also cheat and do it using a detached commit
cd libavr32
git fetch upstream
git checkout upstream/master
cd ..
git add libavr32
git commit -m "updated libavr32 to master"
git push # now go to GitHub and open a PR
When you git pull or git checkout, your submodule won’t update! You need to use the git submodule update command, beware if your submodule is dirty (see the --merge and --rebase options). You’ll find that your life is a lot easier if you don’t work on the master branch.
One final tip:
git config --global status.submoduleSummary true
will change your git status command to show submodule info too.