Skip to content

Add a way for gh repo create to push the HEAD branch #3209

Description

@driesvints

Describe the feature or problem you’d like to solve

After creating a new GitHub repo, the repository is empty. I'd like to have the current HEAD branch pushed to the repo so the repository is already populated with code.

Proposed solution

This will allow people to get started with their new repo that much easily. Maybe one of the following three flags can be considered?

gh repo create --with-head
gh repo create --with-branch
gh repo create -b

Additional context

This is handy for when you're automating things with the CLI and want to have a repository ready to go with populated code. See the discussion in #3088 for extra context.

Activity

  1. vilmibm commented on Apr 21, 2021

    @vilmibm
    Contributor

    I like this idea and would vote for --branch.

  2. added
    coreThis issue is not accepting PRs from outside contributors
    on Apr 21, 2021
  3. mislav commented on Jul 20, 2021

    @mislav
    Contributor

    I also like the idea proposed by @AviFS that gh repo create sets upstream configuration for the current branch so that it can be git pushed without arguments: #2184 (comment)

    Whichever approach we take, I agree it should be easier to push local commits to the newly created repository.

  4. driesvints commented on Jul 20, 2021

    @driesvints
    Author

    Yeah I agree, the upstream should also be set.

  5. AviFS commented on Jul 20, 2021

    @AviFS

    Thanks for the mention!

    I'm not totally clear on git, so just hoping to clarify:

    After creating a new GitHub repo, the repository is empty. I'd like to have the current HEAD branch pushed to the repo so the repository is already populated with code.

    As I understand, you can't push until you have something in your repo. Are you proposing that it would automatically do something like echo "# project-name" > README.md to populate the repo, and then push?

  6. driesvints commented on Jul 20, 2021

    @driesvints
    Author

    @AviFS I'm talking about when you use repo create in a directory with code already present.

  7. AviFS commented on Jul 20, 2021

    @AviFS

    @driesvints But what about when it isn't?

    When you make an empty repo named project-name on GH with the web interface you get two prompts.

    It'd be neat if the CLI could also do the first option for you.

    That way, you could just do mkdir project; cd project; gh repo create and the prompt would set it all up for you.

    Web UI prompts

    …or create a new repository on the command line

    echo "# project-name" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git branch -M main
    git remote add origin https://github.com/AviFS/project-name.git
    git push -u origin main
    

    …or push an existing repository from the command line

    git remote add origin https://github.com/AviFS/project-name.git
    git branch -M main
    git push -u origin main
    
  8. driesvints commented on Jul 22, 2021

    @driesvints
    Author

    But what about when it isn't?

    Ah, I don't really care about that use case myself. You can all decide if you like. I primarily want to find a solution to do the following line in a cleaner way: https://github.com/laravel/installer/blob/81a82f05803d6be1221bd471d241801c393e72b4/src/NewCommand.php#L276

  9. egberts commented on Sep 20, 2021

    @egberts

    @driesvints

    Web UI prompts

    …or create a new repository on the command line

    echo "# project-name" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git branch -M main
    git remote add origin https://github.com/AviFS/project-name.git
    git push -u origin main
    

    …or push an existing repository from the command line

    git remote add origin https://github.com/AviFS/project-name.git
    git branch -M main
    git push -u origin main
    

    Both work really well and probably should be done automatically … somehow. For now, I’ve got a ~/bin/git-github-repo-create.sh that does the above for me.

  10. mislav commented on Jun 21, 2022

    @mislav
    Contributor

    There is now the gh repo create --push flag, which will do git push -u <remote> HEAD after creating a new repository.

  11. driesvints commented on Jun 21, 2022

    @driesvints
    Author

    Amazing, thanks @mislav!

  12. marcusradell commented on Apr 15, 2023

    @marcusradell

    Note that --source is also needed. So full command is:
    gh repo create marcusradell/monadium --public --push --source .

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

    coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions