Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
501 views
in Technique[技术] by (71.8m points)

git - Create a GitHub repository from command line

I have been trying to push my local repo changes to github from command line. I have been away from git for a while now so I don't remember a few things. For the past hour I have been trying to push the repo without creating a remote repo on Github.com. As far as I remember, git push origin master/ git push is enough to push the local changes and if necessary create a repo on the remote server. However git push wouldn't let me push and automatically create the repo.

So to save time, I created remote repo on github.com and add the remote repo url using

git remote add origin https://mygithubrepoUrl.com

and it worked.

Is it necessary to create remote repo on Github and then add this url from command line to push changes? Can't Git automatically create repo and push changes?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to create the repo before pushing, but there's hub that automates this for you:

git init newRepo
cd newRepo
hub create

Use the -p switch to hub create to create a private repository. To push the local master branch, issue:

git push -u origin HEAD

The tool can also create pull requests, open the project page, check the CI status, clone existing repos by specifying only username/repo, and a few more things.

The project page suggests aliasing git to hub (because the latter forwards unknown commands to git), but I don't recommend this, even if just to distinguish "bare" Git commands from the hub candy.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...