E.Beach
E.Beach

Reputation: 1857

Syntax for Git Submodule Foreach Pull?

I've cloned a repository that has submodules in it and the submodules have all been git-inited and git-updated. After a changed has been pushed into one or more submodules (by another machine) I run this command:

git submodule foreach git pull origin master

to get the latest locally - but when I enter into my submodules and do a git status I get a "Not currently on any branch" message. I then have to do a combination of git checkout and git pull to get back on track to the submodule's master branch.

If my goal is to do a "get latest from the main branch" across all of my submodules, what is the correct foreach command?

Edit for Example:

Consider this:

  1. I have a repository A with a submodule B and two machines, Z and Y
  2. I clone the repository and submodule onto Y and Z.
  3. I make a change in B on Y and push it back to the server.

Now, what I'm asking for is the syntax to bring Z up to date and get the latest change in B - in such a way that it can scale for multiple submodules.

Upvotes: 1

Views: 994

Answers (1)

Learath2
Learath2

Reputation: 21343

If I understood you correctly you want to get all changes on all submodules and merge them in. If so git submodule update --merge should do the trick. Not sure why you even tried to use foreach there.

Upvotes: 1

Related Questions