# removed submodules shown as untracked when switching branches

3 messages from 2018-02-22 to 2018-02-23. Participants: Mike Friedrich, Stefan Beller.
Thread: https://gitlist.dev/t/47906

## Mike Friedrich, 2018-02-22 20:26

Subject: removed submodules shown as untracked when switching branches
Message-ID: <6add3709b4eb469bb7c8d6319637b53a@USEPRDEX2.corp.kns.com>
URL: https://gitlist.dev/e/6add3709b4eb469bb7c8d6319637b53a%40USEPRDEX2.corp.kns.com

```
Hi,

When switching clean branches I see untracked files appearing where I expect to see "nothing to commit, working tree clean".
This happens when submodules get removed on one branch but its present in another.
I expect git to either not mark the submodule in git status as untracked or git to remove the submodule as it would for ordinary tracked files which do not exist on a branch anymore.

Tested on Windows with: git version 2.15.1.windows.2
Tested on Ubuntu Linux with same output: git version 2.14.1

Test:
    git init test
    git init submodule
    cd submodule
    touch file.txt
    git add file.txt
    git commit -m "test"
    cd ../test
    touch initial.txt
    git add initial.txt
    git commit -m "initial"
    git checkout -b develop
    git status
    #On branch develop
    #nothing to commit, working tree clean

    git submodule add ../submodule sub
    git add sub
    git commit -m "submodule added"
    git status
    #On branch develop
    #nothing to commit, working tree clean

    git checkout master
    git status
    #On branch master
    #Untracked files:
    #  (use "git add <file>..." to include in what will be committed)
    #
    #        sub/
    #
    #nothing added to commit but untracked files present (use "git add" to track)
    # expected: nothing to commit, working tree clean

    git submodule update
    # (no output)
    git submodule
    # (no output)
    git status
    #On branch master
    #Untracked files:
    #  (use "git add <file>..." to include in what will be committed)
    #
    #        sub/
    #
    #nothing added to commit but untracked files present (use "git add" to track)
    # expected: nothing to commit, working tree clean

    git clean -dfx
    #Skipping repository sub/

Best Regards,
Mike Friedrich


________________________________

This email is non-binding, is subject to contract, and neither Kulicke and Soffa Industries, Inc. nor its subsidiaries (each and collectively “K&S”) shall have any obligation to you to consummate the transactions herein or to enter into any agreement, other than in accordance with the terms and conditions of a definitive agreement if and when negotiated, finalized and executed between the parties. This email and all its contents are protected by International and United States copyright laws. Any reproduction or use of all or any part of this email without the express written consent of K&S is prohibited.

```

## Stefan Beller, 2018-02-22 23:53

Subject: Re: removed submodules shown as untracked when switching branches
Message-ID: <CAGZ79kYS_yJs2uFqLDwCgq4W0HrnMxZcCx8-dTXYf3hpPZYWFg@mail.gmail.com>
URL: https://gitlist.dev/e/CAGZ79kYS_yJs2uFqLDwCgq4W0HrnMxZcCx8-dTXYf3hpPZYWFg%40mail.gmail.com
In-Reply-To: <6add3709b4eb469bb7c8d6319637b53a@USEPRDEX2.corp.kns.com>

```
On Thu, Feb 22, 2018 at 12:26 PM, Mike Friedrich <mfriedrich@kns.com> wrote:

>     git submodule add ../submodule sub
>     git add sub
>     git commit -m "submodule added"
>
>     git checkout master

The original behavior of checkout is to ignore submodules, hence it
will be left alone.
Can you retry this recipe with --recurse-submodules given to checkout.
(Or rather run "git config submodule.recurse true" once)

Thanks,
Stefan

```

## Mike Friedrich, 2018-02-23 00:41

Subject: RE: removed submodules shown as untracked when switching branches
Message-ID: <ed3eddb3da05471c8195326043f46740@USEPRDEX2.corp.kns.com>
URL: https://gitlist.dev/e/ed3eddb3da05471c8195326043f46740%40USEPRDEX2.corp.kns.com
In-Reply-To: <CAGZ79kYS_yJs2uFqLDwCgq4W0HrnMxZcCx8-dTXYf3hpPZYWFg@mail.gmail.com>

```
Thank You. This is interesting. There seems to be also a config option submodule.recurse. I did not know that these options have such an effect on the checkout command.

Best Regards, Mike

-----Original Message-----
From: Stefan Beller [mailto:sbeller@google.com]
Sent: Thursday, February 22, 2018 6:53 PM
To: Mike Friedrich <mfriedrich@kns.com>
Cc: git@vger.kernel.org
Subject: Re: removed submodules shown as untracked when switching branches

On Thu, Feb 22, 2018 at 12:26 PM, Mike Friedrich <mfriedrich@kns.com> wrote:

>     git submodule add ../submodule sub
>     git add sub
>     git commit -m "submodule added"
>
>     git checkout master

The original behavior of checkout is to ignore submodules, hence it will be left alone.
Can you retry this recipe with --recurse-submodules given to checkout.
(Or rather run "git config submodule.recurse true" once)

Thanks,
Stefan

________________________________

This email is non-binding, is subject to contract, and neither Kulicke and Soffa Industries, Inc. nor its subsidiaries (each and collectively “K&S”) shall have any obligation to you to consummate the transactions herein or to enter into any agreement, other than in accordance with the terms and conditions of a definitive agreement if and when negotiated, finalized and executed between the parties. This email and all its contents are protected by International and United States copyright laws. Any reproduction or use of all or any part of this email without the express written consent of K&S is prohibited.

```
