365Git

  1. Search
  2. About
  3. Subscribe
  4. Archive
  5. Random

365Git

Regular small snippets and workflows for Git

My original plan of a post everyday turned out to be unrealistic, but I'll carry on posting as regularly as I can.

Find me @abizern on twitter if you have anything you'd like me to cover.

  • Git submodule foreach – updating many submodules at once

    If you have a repository with many submodules, it’s easy to update them all at once.

    For example: I have my vim dotfiles in a Git repository. Not only does this make it easier for me to keep my vim setup the same across multiple machines, but also lets me add other bundles as submodules which makes it easy to update the bundles and propagate changes.

    Once in a while I go into the repository and run:

    git submodule foreach 'git pull || :'
    

    The foreach command evaluates a shell command in each of the submodules. In this case git pull. The || : (in bash this is ‘or true’) stops the foreach command from terminating because of a non-zero return from the shell command.

    Or, you could avoid the zero return problem by echoing the return value:

    git submodule foreach 'echo `git pull`'
    

    This is just one use of foreach. Since I don’t actually develop the submodules, I can keep the repository tidy by running:

    git submodule foreach 'echo `git gc --aggressive`'
    

    Tagged: git submodule repository pull

    Posted on March 5, 2011 with 19 notes ()

  • Updating all remotes at once.

    Just a quick one.

    Say you have a repository with many remotes. Don’t roll your eyes; it’s very likely if you have many collaborators, or if you’re tracking a popular open source project. To pull down all available changes at once try this:

    git fetch --all

    No surprise about what it does.

    Of course, this is a fetch, not a pull, which is a combination of git fetch and git merge, so after this command, don’t expect that your branches have been magically updated. I’m not a big fan of pull; I much prefer to fetch all changes and then explicitly merge with a chosen branch. In my case this works because I don’t have many tracking branches, because I find I can work just as well with the remote branches directly.

    Tagged: branch fetch git pull remote update day8

    Posted on March 31, 2010 with 2 notes ()

Field Notes Theme. Designed by Manasto Jones. Powered by Tumblr.