Skip to content

Suggestion: Automatically create a new Git repository and add initial files #1244

Closed

Description

@mauricedb

One of the nice small things with the Angular CLI is that it automatically creates a new Git repository and adds the initial files to it as the initial commit after initializing a new project. It is not a major thing but it is something I find myself doing pretty much every time I create a new project, even if it is just for test purposes as it makes it easy to see what I changed.

Is this something other people would be interested in seeing me add?

Activity

  1. OskarKlintrot commented on Dec 12, 2016

    @OskarKlintrot

    Maybe it can be a flag so that it can be turned on/off as people prefers? Maybe something like create-react-app hello-world --noGit

  2. gaearon commented on Dec 12, 2016

    @gaearon
    Contributor

    We generally try to avoid flags.

    I think there was a discussion about initializing git earlier in #385.

    I’m down to do this by default if we also solve this:

    From my personal experience most of the time the React client code is part of a bigger project with server code that is already under version control. Also there are a lot of people using Mercurial.

    So if we’re inside a Git/Hg project we shouldn’t try to initialize a new repo.

  3. OskarKlintrot commented on Dec 12, 2016

    @OskarKlintrot

    That makes sense, the reason for my flag-idea was, just like you said, that you might want to use it in an existing repo.

  4. gaearon commented on Dec 12, 2016

    @gaearon
    Contributor

    We should be able to detect this. After all, Git/Hg somehow detect they’re inside repos 😉 .

  5. OskarKlintrot commented on Dec 12, 2016

    @OskarKlintrot

    That .git folder might have something to do with it 😉

  6. mauricedb commented on Dec 12, 2016

    @mauricedb
    ContributorAuthor

    In the Angular CLI they run git rev-parse --is-inside-work-tree to see if they are already in a Git repo, see here.

    If already in a Git repo we could do a git add . and git commit which would be fine if there is nothing added yet. However if there are other changes already added they would get committed as part of the same commit. I would prefer to do nothing in that case and just let the user decide.

    Not sure why I didn't see #385. I did search but did not come across that issue. From reading that I would not be in favor of adding a remote. Quite often I am just experimenting and even if I want to push it to a remote I might use BitBucket or some other alternative over GitHub. I would keep it very similar to what the Angular CLI does: Create a new repo if not already in one and add the generated code as the initial commit.

    From the last comment by @mareksuscak I am unsure how much work he already did do. Don't want to start two PR's that compete with each other.

  7. gaearon commented on Dec 13, 2016

    @gaearon
    Contributor

    I would keep it very similar to what the Angular CLI does: Create a new repo if not already in one and add the generated code as the initial commit.

    👍

    From the last comment by @mareksuscak I am unsure how much work he already did do. Don't want to start two PR's that compete with each other.

    @mareksuscak can you give us some context?

  8. mareksuscak commented on Dec 13, 2016

    @mareksuscak
    Contributor

    I haven't done anything beyond examining how ember-cli does the same thing. I made a skeleton but I think I removed the branch afterward so go ahead if you're in a hurry.

  9. Timer commented on Dec 13, 2016

    @Timer
    Contributor

    I think it's important to have an opt-out for this feature, because I wouldn't want the CLI making the first commit.
    I feel like part of my regular workflow would become create-react-app app1 && cd app1/ && rm -rf .git/ then init the repo myself.

  10. gaearon commented on Dec 13, 2016

    @gaearon
    Contributor

    @Timer Curious why? You could always amend it..

  11. Timer commented on Dec 13, 2016

    @Timer
    Contributor

    @gaearon main reason is that I want very specific files to be present in the first commit; namely simply a LICENSE file and possibly a bare README.

    Not to mention I would like myself to be the root author; not the CLI.
    In this situation -- removing .git and starting from scratch seems easier than amending the first commit to my liking.

    It seems like we're introducing much more complexity versus someone just typing git init and doing their own thing.

  12. gaearon commented on Dec 13, 2016

    @gaearon
    Contributor

    In this situation -- removing .git and starting from scratch seems easier than amending the first commit to my liking.

    Isn't it as easy as passing --amend to your first commit? Not trolling, genuinely curious.

    I would like myself to be the root author; not the CLI.

    That’s how I’d imagine it working.

  13. Timer commented on Dec 13, 2016

    @Timer
    Contributor

    @gaearon I often utilize many different emails depending on the repository, so I'd be amending with additional flags such as --author "".

    It's not super easy to remove a file from the first commit, because you can't (as far as I know) rewind the commit via standard git reset --[soft/mixed] HEAD^.

    The process is more convoluted, requiring the user to run git rebase --root -i and selecting to edit the root commit, then running git reset [files] for the files they want to remove followed by git commit --amend and git rebase --continue.


    I would love for someone to improve my knowledge of git, but I dunno how to do this without the latter.

  14. Timer commented on Dec 13, 2016

    @Timer
    Contributor

    That’s how I’d imagine it working.

    This was more of an assumption from the existing CLIs, which seem to commit it as a user/email of the CLI (e.g. create-react-app and cli@create.react.app) and not your global user.name and user.email.

    Notice the committer (I realize now you said "... sans the Tomster ..."):

  15. mauricedb commented on Dec 13, 2016

    @mauricedb
    ContributorAuthor

    @mareksuscak, Not in a hurry or so but I will go ahead and start this and create a PR.

    @Timer and @gaearon, Both the Ember and Angular CLI create a commit with the CLI as the author and the current user as the committer. I would argue that is correct as the user didn't write a single line of code yet, the CLI did that. But personally I don't care very much and would be happy with just the commit message stating that it was an initial commit from Create-React-App.

    @Timer, As far as I can tell you can remove files from the first commit without any problem. Just did a quick test after an ng new test-app. Added a file, deleted one and changed a third and did a git commit --amend and the result was exactly as I expected. The changes, including the delete, where part of the initial commit and the commit headers where unchanged.

  16. Timer commented on Dec 13, 2016

    @Timer
    Contributor

    Yes @mauricedb, but what if I want to remove a file from the initial commit while keeping it in my local directory?

    e.g. CLI commits LICENSE, README.md and index.js.
    I want to make the first commit contain only LICENSE and README.md, and the second commit index.js. But I don't want to go through the extra steps of doing cp index.js index.js.bak, git rm index.js, git commit --amend, mv index.js.bak index.js, git add index.js, git commit -m "Add index.js". Now multiply this process by 10 files w/ different extensions.

    In that scenario I'd just do rm -rf .git/, git init, git add LICENSE README.md, git commit -m "Initial commit".

  17. mauricedb commented on Dec 13, 2016

    @mauricedb
    ContributorAuthor

    @Timer, Right I misunderstood your goal. In that case I believe you are right and there is no simple way with git. I think the scenario you describe could be the easiest option. But it feels weird to delete a git repo so you can create one.

  18. gaearon commented on Dec 13, 2016

    @gaearon
    Contributor

    I feel like people caring that much about what goes into initial commit is going to be a tiny minority of our users. But maybe I’m wrong.

  19. mauricedb commented on Dec 13, 2016

    @mauricedb
    ContributorAuthor

    @gaearon, That is my gut feeling as well but have no data to back it up.

    There is a relatively simple workaround with the steps @Timer suggests. Personally I would not make this configurable through a command line option unless there was more demand for it. And adding an opt-out option should be easy in a future PR.

  20. Timer commented on Dec 13, 2016

    @Timer
    Contributor

    I'm sure there will be very few complaints about it and I'm not trying to talk anyone out of implementing this.

    Please understand most of my comments were not an argument but simply an elaboration when asked. Anyway, I think this would be a good default and me removing .git/ or passing a flag is probably similar in keystrokes so I'm indifferent about an option being added.

  21. mauricedb commented on Dec 15, 2016

    @mauricedb
    ContributorAuthor

    @gaearon

    I have the changes in a branch that should work but I am running into issues testing if it really works the way it is supposed to. I wanted to test using npm run create-react-app ../test1 but can't do so on my laptop because I am running Windows 10 and that calls a Bash script.

    So I tried running it in a Linux Docker container but not having much luck there either. Using the following commands:

    docker run -it -v c:/Repos/create-react-app:/repos/create-react-app node bash
    cd /repos/create-react-app
    npm run create-react-app ../test1
    

    I see the following error:

    sh: 1: tasks/cra.sh: not found
    

    Even though the file is there.

    My branch is here: https://github.com/mauricedb/create-react-app/tree/git-init

  22. santhoshsiddamshetty commented on Jun 21, 2018

    @santhoshsiddamshetty

    Local workspace file ('angular.json') could not be found.
    Error: Local workspace file ('angular.json') could not be found.
    at WorkspaceLoader._getProjectWorkspaceFilePath (C:\Users\SS\AppData\Roaming\npm\node_modules@angular\cli\models\workspace-loader.js:37:19)
    at WorkspaceLoader.loadWorkspace (C:\Users\SS\AppData\Roaming\npm\node_modules@angular\cli\models\workspace-loader.js:24:21)
    at ServeCommand._loadWorkspaceAndArchitect (C:\Users\SS\AppData\Roaming\npm\node_modules@angular\cli\models\architect-command.js:180:32)
    at ServeCommand. (C:\Users\SS\AppData\Roaming\npm\node_modules@angular\cli\models\architect-command.js:47:25)
    at Generator.next ()
    at C:\Users\SS\AppData\Roaming\npm\node_modules@angular\cli\models\architect-command.js:7:71
    at new Promise ()
    at __awaiter (C:\Users\SS\AppData\Roaming\npm\node_modules@angular\cli\models\architect-command.js:3:12)
    at ServeCommand.initialize (C:\Users\SS\AppData\Roaming\npm\node_modules@angular\cli\models\architect-command.js:46:16)
    at Object. (C:\Users\SS\AppData\Roaming\npm\node_modules@angular\cli\models\command-runner.js:87:23)

  23. locked and limited conversation to collaborators on Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions