Easier way to update submodules in git

I love using git submodules to avoid duplicating common code. Unfortunately, updating a submodule reference to the lastest revision is a chore:

cd framework
git checkout master
git pull
git submodule update --init --recursive
cd ..

However, we can store all of those commands using a git alias:

git config --global alias.up-sub '!f() { cd $1 && git checkout master && git pull && git submodule update --init --recursive; }; f'

Now, to update the ‘framework’ submodule, we can just do:

git up-sub framework

I picked up the trick for running multiple commands in an alias from this article on the Mozilla blog.

Update Use && instead of ; to prevent losing work when you mistype the submodule name.

comments powered by Disqus