44

How can I update git sub modules in SourceTree?

nwellnhof
  • 32,319
  • 7
  • 89
  • 113
wnrph
  • 3,293
  • 4
  • 26
  • 38

6 Answers6

41

I couldn't find the answer myself, so I created a custom action. Go to Preferences, Custom Actions, and enter the following info: (This is on a Mac. Your path to the git executable may vary.) git submodule update custom action

edmengel
  • 536
  • 5
  • 4
  • 6
    you also may want to use "submodule update --init --recursive". It is harmless to add "--init" if an initialization has already been done, and it may be necessary if you freshly cloned a repo with submodules. "--recursive" is harmless if you don't have submodules which reference other submodules, and essential if you do. – ctpenrose Feb 26 '14 at 19:48
23

Just double-click on the submodule or left-click and open the module enter image description here

Once in the submodule, the UI is like any git repo , press on pull/fetch to update to the header. And voila.

Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110
  • 3
    Are you sure this does what `git submodule update` does? At any event, I don't like to `git fetch` or `git pull` (because these would disregard the revision indicated by the containing repository.) – wnrph Dec 10 '12 at 11:55
  • good question !! Coming from subversion , I did not know the difference between "fetch" and "update". Take a look https://answers.atlassian.com/questions/33274/sourcetree-updating-submodules-when-pulling-from-a-repository – Raymond Chenon Dec 12 '12 at 10:56
  • 3
    This will checkout the latest version if you ask me, not checkout the commit which is committed in the main repo. – Ambidex Jun 25 '14 at 13:09
  • 3
    This is exactly what I was looking for, and it's also described in [the documentation](https://blog.sourcetreeapp.com/2012/02/01/using-submodules-and-subrepositories/). *"If there are new changes in the submodule which you want to use in your repository, all you have to do is open the submodule (double-click) and checkout/update to a different commit, either via pull, merge or just manually checking a commit out ... Once you have done this, return to the parent repository and you will see an uncommitted change on the submodule, which will show in the diff the change in tracked commit:"* – GolezTrol Feb 21 '16 at 23:16
  • 6
    The goal of `git submodule update` is to switch to the *version specified in the parent repo*. (That is good for consumers who just want to use the recommended submodule.) Pulling on the other hand will bring the *latest version* from the upstream repository. (This is better if you want to work on the submodule, or if you want to use the latest version regardless of which version the parent repo specifies.) – joeytwiddle Aug 07 '17 at 11:38
10

Here is the version:

enter image description here

This command assumes the location of your sh.exe - depending on how you setup SourceTree it could be somewhere else.

/c %LOCALAPPDATA%\Atlassian\SourceTree\git_local\bin\sh.exe --login -i -c "git submodule update"""

Not sure whether it is a bug - but in the version of Sourcetree I am using (v1.6.14.0) I found that having the extra pair of quotations "" on the end was required - otherwise an extra quotation exists and the unbalanced statement then causes sh to bark:

cmd "/c %LOCALAPPDATA%\Atlassian\SourceTree\git_local\bin\sh.exe --login -i -c "git submodule update""
sh: unexpected EOF while looking for matching `"'
sh: syntax error: unexpected end of file

Completed with errors, see above.
dtmland
  • 2,136
  • 4
  • 22
  • 45
  • Doesn't seem to work, but that's maybe because SourceTree adds an extra pair of quotes around the whole parameter string. – GolezTrol Feb 21 '16 at 23:12
7

I'm using source tree v3.4.6, you can enable it via menu Tools\Options enter image description here

When clone, you should enable Recurse submodules enter image description here

Cong Dan Luong
  • 1,577
  • 17
  • 15
6

The link provided by Isuru does include how to perform update (look for "Change the submodule commit which your repository is tracking")

In short, on the main repository,

  • choose the submodules dropdown
  • double click the submodule you want to update - you will switch focus to the submodule
  • pull (latest) or checkout (specific commit) the required update
  • go back to the tab for the main repository
  • there will be an uncommitted change (which submodule commit to use) in the main repository
  • commit and push the change
CharlieBird
  • 73
  • 1
  • 4
0

From the list of Unstaged files, right-click the submodule you want to update and select "Discard". This will do a git submodule update.

marsl
  • 959
  • 1
  • 14
  • 25