Can I create a remote warehouse on GitHub from CLI without opening a browser?

I created a new local Git Repository:

~$ mkdir projectname
~$ cd projectname
~$ git init
~$ touch file1
~$ git add file1
~$ git commit -m 'first commit'

Is there any git command to create a new remote warehouse and push my submission to GitHub from there? I know to launch the browser and turn to Create a new repository It's no big deal, but I would be happy if there was a way to do this from CLI.

I read a lot of articles, but I didn't mention how to use the git command to create a remote warehouse from CLI. Good article by Tim Lucas Set up a new remote git repository It's the closest I've found, but GitHub doesn't provide shell access.

#1 building

CLI command for github API v3 (replace all CAPS keywords):

curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}'
# Remember replace USER with your username and REPO with your repository/application name!
git remote add origin git@github.com:USER/REPO.git
git push origin master

#2 building

For instructions on creating tokens, go to here This is the command you want to type as of the date of this reply. (replace all CAPS keywords):

curl -u 'YOUR_USERNAME' -d '{"scopes":["repo"],"note":"YOUR_NOTE"}' https://api.github.com/authorizations

After entering the password, you will see the following that contains the token.

{
  "app": {
    "name": "YOUR_NOTE (API)",
    "url": "http://developer.github.com/v3/oauth/#oauth-authorizations-api"
  },
  "note_url": null,
  "note": "YOUR_NOTE",
  "scopes": [
    "repo"
  ],
  "created_at": "2012-10-04T14:17:20Z",
  "token": "xxxxx",
  "updated_at": "2012-10-04T14:17:20Z",
  "id": xxxxx,
  "url": "https://api.github.com/authorizations/697577"
}

You can be there any time Here Revoke your token

#3 building

If you install defunkt excellent Hub Tools, it's so easy

git create

In the author's words, "hub is git's command-line wrapper, which can make you better on GitHub."

#4 building

I wrote a beautiful script named Gitter for GitHub and BitBucket using the REST API:

https://github.com/dderiso/gitter

Barrels in place:

gitter -c -r b -l javascript -n node_app

GitHub:

gitter -c -r g -l javascript -n node_app
  • -c = create new repo
  • -r = repo provider(g = GitHub,b = BitBucket)
  • -n = named repo
  • -l = (optional) set the language of the application in repo

#5 building

Be based on Bennedich's answer , I've created a Git alias to do this. Add the following to ~ /. gitconfig:

[github]
    user = "your_github_username"
[alias]
    ; Creates a new Github repo under the account specified by github.user.
    ; The remote repo name is taken from the local repo's directory name.
    ; Note: Referring to the current directory works because Git executes "!" shell commands in the repo root directory.
    hub-new-repo = "!python3 -c 'from subprocess import *; import os; from os.path import *; user = check_output([\"git\", \"config\", \"--get\", \"github.user\"]).decode(\"utf8\").strip(); repo = splitext(basename(os.getcwd()))[0]; check_call([\"curl\", \"-u\", user, \"https://api.github.com/user/repos\", \"-d\", \"{{\\\"name\\\": \\\"{0}\\\"}}\".format(repo), \"--fail\"]); check_call([\"git\", \"remote\", \"add\", \"origin\", \"git@github.com:{0}/{1}.git\".format(user, repo)]); check_call([\"git\", \"push\", \"origin\", \"master\"])'"

To use it, run

$ git hub-new-repo

From anywhere in the local repository, and enter your Github password when prompted.

Keywords: git github curl shell

Added by info@ipfaces.org on Sun, 08 Mar 2020 12:19:42 +0200