124

Error

Repository is not clean. Please commit or stash any changes before updating

when i have updated from version 7 to Angular 8.

Angular Guide for upgrade https://update.angular.io/#7.0:8.0

  D:\app-test> ng update @angular/cli @angular/core
               npm cache verify

Repository is not clean. Please commit or stash any changes before updating.

Update Version

    PS D:\app-test> ng update
                Using package manager: 'npm'
                Collecting installed dependencies...
                Found 58 dependencies.
                    We analyzed your package.json, there are some packages to update:

                      Name                               Version                  Command to update
                     --------------------------------------------------------------------------------
                      @angular/cdk                       7.2.2 -> 8.0.1           ng update @angular/cdk
                      @angular/core                      7.2.15 -> 8.0.1          ng update @angular/core
                      @angular/core                      7.2.2 -> 7.2.15          ng update @angular/core
                      @angular/material                  7.3.7 -> 8.0.1           ng update @angular/material
                      rxjs                               6.3.3 -> 6.5.2           ng update rxjs


                    There might be additional packages that are outdated.
                    Run "ng update --all" to try to update all at the same time.

                PS D:\app-test> ng update @angular/cdk
                Repository is not clean.  Please commit or stash any changes before updating.

i have checked git was not installed in project.

solution that worked

   git commit 

After Googling i have This is happening After Angular 8.

Bug

https://github.com/angular/angular-cli/issues/14600

Sathiamoorthy
  • 6,942
  • 6
  • 53
  • 64
afeef
  • 3,858
  • 9
  • 33
  • 61
  • this is bug in angular 8 https://github.com/angular/angular-cli/issues/14600 – afeef Jul 03 '19 at 08:37
  • Does this answer your question? [ng update --all does say 'Repository is not clean' evendought git commit](https://stackoverflow.com/questions/56531262/ng-update-all-does-say-repository-is-not-clean-evendought-git-commit) – J J B Jan 16 '20 at 17:09

8 Answers8

237

It's a bug in Angular 8

you can work around it by using:

ng update @angular/cli @angular/core --allow-dirty

beta
  • 2,473
  • 15
  • 33
  • 46
Abdullah Adeeb
  • 3,046
  • 1
  • 13
  • 13
64

I have tried using mention command for upgrading from angular 8 to angular 9, but was still getting the error.

Then i have tried same command with --force flag and it worked for me.

ng update @angular/cli @angular/core --allow-dirty --force
sharad jain
  • 1,211
  • 12
  • 8
46

I've had the same issue. It's a common bug in Angular 8. Simply you can use dirty commands to bypass the repo check, such as (if u really need to bypass this, follow force commands)

ng update @angular/cli @angular/core --allow-dirty or
ng update @angular/cli @angular/core --allow-dirty --force

but, I didn't do that. I followed following steps...

first of all double check whether you are commited all the changes before the update.then keep a copy of the project to the same location and commit the copy also to the Git. then run following command from the original project directory

ng update @angular/core@8 @angular/cli@8

afterwards u can delete the copy. This worked for me! thank you!

MrMalith
  • 1,132
  • 13
  • 22
9

I faced the same issue, which I resolved using the below command

git stash --include-untracked
Sathiamoorthy
  • 6,942
  • 6
  • 53
  • 64
  • 1
    Note that the `save` option for `git-stash` is [deprecated](https://stackoverflow.com/a/47231547) from Git 2.15/2.16 (Q1 2018) in favour of `git stash push` (or `git stash`). – Edric Oct 23 '20 at 02:45
  • I removed it from the answer, thanks @Edric. – Yona Appletree Dec 08 '21 at 04:13
2

Worked for me

sudo npm update @angular/cli @angular/core --allow-dirty --legacy-peer-deps
jonathasborges1
  • 1,833
  • 2
  • 6
  • 13
1

in my case, this was due to a node_modules folder not being excluded by the .gitignore. once added, this error no longer appeared

jgritten
  • 820
  • 11
  • 19
0

It might appear in many cases. Just commit or stash any changes and run the command again.

Experimenter
  • 1,607
  • 15
  • 22
-1

First, Check if there are any changes in your code that haven't pushed to git if yes push them, then close the old instance(cmd) and open a new instance of cmd then run the command. This worked for me, Thanks