Useful git commands – part 2

Sometimes you have a project with lots of submodules that you never change yourself, but want to update occasionally. One example would be if you use Pathogen for your VIM plugins. You’d think you could use git submodule update here, and sometimes you can. But note that one of the main features of submodules is that they are locked to a particular commit. In case you want to pull in the latest changes from the remote, you need something else.

I put this alias in my .gitconfig file to solve the problem (note that this needs to be all on one line):

subup = submodule foreach 'git pull -s recursive 
-X theirs origin master'

The command will cd into each submodule, and do a forced pull overwriting any local changes you may have. Nice, right?

Useful git commands – part 1

If you are like me, you have a whole bunch of projects on your hard disk that you want to update occasionally, but don’t really work actively with. Previously I usually put an update-all.sh file in the root folder of those projects. But in most cases it is possible to use a general approach. I now do it like this:

If you pass a path to the script, it updates all subdirectories under that path, else it uses the current directory. And to make it even more convenient, you can add an alias to your .gitconfig file, like so:

pullall = !~/bin/git-pullall.sh

Now you can just use git pullall to update everything in one go. Convenient!