How do I git clone --recursive and checkout master on all submodules in a single line?

I really like this command to fetch a repo with submodules:

git clone [email protected]:my_user/my_repo.git --recursive

However, the submodules are all set to "no branch" when they arrive, and I have to manually checkout master on each and every one. Is there a way to recursively pull submodules and automatically set the branch to master?

-------------Problems Reply------------

How about:

git submodule update --init --recursive

To initialize all submodules and submodules inside submodules. Not sure if this will checkout master though.

The question is why you checkout master. Your sub modules are pinned to a specific sha - that's also why the sub module clones are fixed to that specific commit. By not pointing to a specific sha an external repo could easily break your builds. Most definitely not what you want. Better update consciously. Builds should be reproducible and as fix as possible.

After cloning the repository containing your submodules, the following command will checkout the master branch on all of these in one go:

git submodule foreach --recursive git checkout master

Perhaps you should consider gitslave as an alternative to git-submodule, depending on your development workflow it may be better (or worse). Specifically to your issue, gitslave keeps all members of the superproject on the same branch (absent specific git (not gitslave) commands to do otherwise, and even then many commands warn you when you are on different branches).

Gitslave is useful when you control and develop on the subprojects at more of less the same time as the superproject, and furthermore when you typically want to tag, branch, push, pull, etc all repositories at the same time.

git-submodule is better when you do not control the subprojects or more specifically wish to fix the subproject at a specific revision even as the subproject changes.

Category:git Views:3 Time:2011-06-24

Related post

  • Why are all of my git submodles not being cloned when I do git clone --recursive? 2010-12-15

    I tried to export my emacs and vim configurations into their own repositories, and added them as submodles to a superrepository. However when I try to do git clone --recursive to clone the superrepository, it only pulls in the ext/rsense submodule an

  • git-clone and post-checkout hook 2010-01-26

    According to the manual, the post-checkout hook is run after a git checkout (just as expected) but also after a git clone (unless you pass --no-checkout). Very well, now, considering the following: you don't have a local repository before a git clone

  • git clone does not checkout active branch 2011-08-03

    I have a remote bare repository with two branches 'master' and 'testing', where HEAD refers to 'testing'. When cloning this repository git checks out 'master', if 'master' and 'testing' are on the same revision (i.e. HEAD == testing == master). Only

  • Can I add a username & password to git clone using the --recursive option (for submodules)? 2011-03-24

    I am using git to clone a repo via https thus: git clone https://username:[email protected]/git/repo.git This is fine but it has a large number of subrepos to clone as well so I am using the --recursive option. Problem here is that for the top level

  • How to `git clone` including submodules? 2010-09-26

    I'm trying to put a submodule into a repo. The problem is that when I clone the parent repo, the submodule folder is entirely empty. Is there any way to make it so that 'git clone parent' actually puts data in the submodule folder? example: http://gi

  • git clone: fatal: Unable to find remote helper for 'https' 2011-11-30

    I am unable to clone HTTPS repositories. I can clone SSH repos fine, but not HTTPS repos. I cannot test the GIT protocol since I am behind a corporate firewall. This is what I am trying to do: $ git clone https://github.com/nvie/gitflow.git Cloning i

  • How to complete a git clone for a big project on an unstable connection? 2010-10-17

    I am trying to git clone the LibreOffice codebase, but at the moment I have an internet connection by mobile phone of about 300kbps and it's just anything but stable. I can get the connection back any moment, but then the git clone process already st

  • Clone local SVN checkout to GIT 2010-07-21

    We have a remote SVN repository that is used to hold all our content form artwork to videos etc... As you would expect this remote SVN repository is 90 gigs in size. I would like to use GIT instead of using SVN, considering I would like to have any u

  • What is the difference between git clone and checkout? 2011-09-04

    I had been using SVN and VSS for years and getting into open source now a days. It looks like although Apache code is hosted in SVN, many use Git so that they can work offline and some other benefits. So, I started reading a bit about Git and got con

  • git: clone ony a subdirectory 2009-03-01

    I have my git repo which, at the root, has two sub-dirs /finisht /static When this was in SVN, /finisht was checked out in one place, while /static was checked out elsewhere, like so: svn co svn+ssh://[email protected]/home/admin/repos/finisht/static

  • git clone of git-svn tree? 2009-02-20

    I've got a 'git-svn' working tree. I'd like to clone a "pure" git repo off this, and then use git push/pull to move changes between the git-svn tree and the git tree, while also using 'git svn dcommit/rebase' to move changes between the git-svn tree

  • Hudson git clone error 2009-07-24

    I have created free-style software project in Hudson. I want to clone a public Git repository: git://github.com/bret/watir.git Build fails with error message: Started by user anonymous Checkout:workspace / C:\Documents and Settings\Administrator\.hud

  • how can i git clone git://foo.git AGAIN? 2009-08-08

    I did git clone git://foo.git cd foo ...edit files.. now I want to start fresh. I don't care about any changes I already made, but I don't want to clone the whole giant foo.git again, just lose all my changes. how can i git clone git://foo.git a seco

  • Can I do 'git svn dcommit' from a SVN git clone which was created with --no-metadata? 2009-10-16

    I converted a SVN repository to git using git svn clone --stdlayout --authors-file=authors.txt --no-metadata svn://svn.foo.com For some reason, this gave me what looked like a bare repository. There was just a .git directory. In thise cloned reposito

  • Git clone fails due to untracked files but all branches are clean 2010-01-05

    I am attempting to clone a git repository. The clone fails with the following message: Untracked working tree file ... would be overwritten by merge. I have run git clean on all of the branches; none have untracked files. The file which is labeled un

  • git clone overwrote an existing repo with the same name 2010-06-25

    it had a existing git checkout and had made some modifications, then i checked out the same repo and it overwrote the folder. Is there some way to get the old repos with the uncommitted changes? I had checked " git reflog --all " but it only gave me

  • Merge, update, and pull Git branches without using checkouts 2010-07-09

    I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do: git merge origin/branchB However, I would also like to keep a local copy of branch B, as I may occas

  • git: how to update (checkout) a single file from remote origin master 2010-07-26

    The scenario: I make some changes in a single file locally and run git add, git commit and git push The file is pushed to the remote origin master repository I have another local repository that is deployed via capistrano with the "remote_cache" meth

  • Git clone particular version of remote repository 2010-08-24

    I am very new to the world of git and version control. I cloned a remote git repository about a month ago. The remote repository has undergone many changes and has now become unstable. Now I need another copy of the repository, version identical to t

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.089 (s). 11 q(s)