Skip to content

ng new --skip-git/--skipGit should not skip creating .gitignore file #8638

Description

@ADTC

Versions

Angular CLI: 1.5.3                                           @angular/cli: 1.5.3
Node: 8.9.1                                                  @angular-devkit/build-optimizer: 0.0.33
OS: win32 x64                                                @angular-devkit/core: 0.0.21
Angular: 5.0.3                                               @angular-devkit/schematics: 0.0.37
... animations, common, compiler, compiler-cli, core, forms  @ngtools/json-schema: 1.1.0
... http, language-service, platform-browser                 @ngtools/webpack: 1.8.3
... platform-browser-dynamic, router                         @schematics/angular: 0.1.7
                                                             typescript: 2.4.2
Windows 10 x64                                               webpack: 3.8.1

Repro steps

  1. Use ng new --skip-git to create a new project without a Git repository.
  2. Open the project folder and look for .gitignore file.

Observed behavior

The .gitignore file does not exist.

Desired behavior

What would like to see implemented?

The .gitignore file should be generated and added to the project.

What is the use case?

  • Project may be part of a larger project that already has a Git repository.
  • Project may have a Git repository initialized later.

What did you expect to see?

The .gitignore file exists.

Mention any other details that might be useful (optional)

A .gitignore file is still very useful even if no Git repository was initialized. This is because the project may be part of a larger project which already has a Git repository or uses another gitignore-aware VCS. Or a Git repository may be added to the project later. In either case, you do not want all the build files, modules, IDE files, e2e files and whatnot to be checked in to the repository.

For anyone that may never use Git with the project, the .gitignore file is just a small harmless additional file in the project, so it's not an issue there.

Relates to #4854

Activity

  1. Survivedabuse commented on Nov 26, 2017

    @Survivedabuse
  2. beeman commented on Nov 26, 2017

    @beeman
    Contributor

    This is by design #3713

  3. ADTC commented on Nov 26, 2017

    @ADTC
    Author

    I now understand it's by design. But what about the use cases I had described?

  4. beeman commented on Nov 27, 2017

    @beeman
    Contributor

    @ADTC I think this is such a specific use case that the best option would be to not use the --skip-git flag and just rm -rf .git after you ran the ng new command.

    If it's part of a bigger repo you might have to customize it already, the Angular CLI aims to set defaults that work for most situations, but it can never accommodate to any situation.

    @Brocco might have more ideas about it.

  5. Executus commented on Apr 30, 2018

    @Executus

    Here's another use case using VSTS (Visual Studio Online):

    1. Create empty git project in VSTS
    2. Clone git project on client
    3. Create angular app with --skip-git flag, as we don't want to init a new repo. However we still want the gitignore.
  6. NeeLonGithub commented on Jun 9, 2019

    @NeeLonGithub

    I expect --skip-git to skip the git processes (init and first commit).
    In my case I just don't want the first commit to be done with my global settings, so I want to skip the git processes and do them myself later.
    For an option that expects the project to be oblivious of git and therefore not even create a .gitignore, I would expect --no-git or something similar.

  7. added
    featureLabel used to distinguish feature request from other issues
    and removed
    needs: investigationRequires some digging to determine if action is needed
    on Oct 8, 2019
  8. modified the milestone: Backlog on Oct 8, 2019
  9. dgp1130 commented on Jun 26, 2020

    @dgp1130
    Collaborator

    Discussed this in a CLI meeting today. Unfortunately not much justification was given in the original PR, so it's hard to know the major reasons for removing .gitignore beyond "It's related to Git".

    In our discussion, we had the following points:

    • It's easier to delete than to add .gitignore for Angular's specific file structure.
    • IDEs and tools often use .gitignore to filter unwanted files.
    • The existing --skip-package-manager flag just skips the npm/yarn binary, it still generates package.json. So having --skip-git just skip the git init call but create .gitignore would be more consistent.

    OTOH:

    • If you're using a different VCS, you'd not want to bother with .gitignore at all (though no other VCS is directly supported right now).
    • We could add another flag (for example --no-git) as someone suggested, but this would be very confusing when compared to the existing --skip-git and the subtle distinction between them would hard to communicate to users.
    • Changing the existing behavior does cause some churn in the ecosystem and user base.

    Users could be creating an Angular application in a directory already under source control, though we already handle that today and include .gitignore while skipping git init. So I think we're already doing the right thing here without needing the user to specify an extra flag.

    douglasparker@basilisk (~/Source)                                                                        
    [20-06-26 10:15:05]$ mkdir git
    mkdir: created directory 'git'
    douglasparker@basilisk (~/Source)
    [20-06-26 10:15:08]$ cd git/                                                                           
    douglasparker@basilisk (~/Source/git)
    [20-06-26 10:15:10]$ git init                                                                            
    Initialized empty Git repository in /home/douglasparker/Source/git/.git/                                 
    douglasparker@basilisk (~/Source/git)                                                                    
    [20-06-26 10:15:13]$ ng new --defaults ng
    # ...
    CREATE ng/.gitignore (631 bytes)
    # ...
    ✔ Packages installed successfully.
        Directory is already under version control. Skipping initialization of git.
    

    There's also the somewhat related question of app/assets/.gitkeep, which is also related but doesn't have the same benefits as .gitignore. It's just there so the assets/ folder gets committed.

    Based on these points, the consensus of the team is to include .gitignore even when --skip-git is requested. IDEs and other tools will generally work better with this file present and it is trivial to delete it if the user really doesn't want it. If we support other VCS tools in the future, then we may want to revisit this decision.

  10. removed
    needs: discussionOn the agenda for team meeting to determine next steps
    on Jun 26, 2020
  11. changed the title [-]ng new --skip-git should not skip creating .gitignore file[/-] [+]ng new --skip-git/--skipGit should not skip creating .gitignore file[/+] on Jul 6, 2020
  12. alan-agius4 commented on May 26, 2021

    @alan-agius4
    Collaborator

    Closing as per above.

  13. angular-automatic-lock-bot commented on Jun 26, 2021

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  14. locked and limited conversation to collaborators on Jun 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions