Repository navigation
Add a way for gh repo create to push the HEAD branch #3209
Description
Activity
I like this idea and would vote for
--branch.Reacted by Dries Vints- addedcoreThis issue is not accepting PRs from outside contributorsThis issue is not accepting PRs from outside contributors
on Apr 21, 2021 I also like the idea proposed by @AviFS that
gh repo createsets upstream configuration for the current branch so that it can begit pushed without arguments: #2184 (comment)Whichever approach we take, I agree it should be easier to push local commits to the newly created repository.
Reacted by Avi Sternlieb and chandrawisnuYeah I agree, the upstream should also be set.
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.mdto populate the repo, and then push?@AviFS I'm talking about when you use repo create in a directory with code already present.
@driesvints But what about when it isn't?
When you make an empty repo named
project-nameon 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 createand 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 mainReacted by EgbertBut 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
Reacted by Mislav Marohnić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 mainBoth 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.
There is now the
gh repo create --pushflag, which will dogit push -u <remote> HEADafter creating a new repository.Reacted by Dries VintsReacted by Dries VintsAmazing, thanks @mislav!
Note that
--sourceis also needed. So full command is:
gh repo create marcusradell/monadium --public --push --source .
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?
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.