← back to the blog


Create a new git repository from command line (curl)

Posted on November 18th, 2019 in Miscellaneous by George

 

So one line in the terminal is required and also you are prompted to insert the password for your git account.

 

curl -u 'yourGithubUserNameHere' https://api.github.com/user/repos -d '{"name":"newRepositoryName"}'

 

The JSON object used at the end of the command can take more than one option.

In our case, we specified the name but can add take other options like private: true/false.

This is the output you will get in the console:

Georges-MBP:Projects georgerdp$ curl -u 'GeorgeCrisan' https://api.github.com/user/repos -d '{"name":"temprepo"}'
Enter host password for user 'GeorgeCrisan':
{
  "id": 222547015,
  "node_id": "MDEwOlJlcG9zaXRvcnkyMjI1NDcwMTU=",
  "name": "temprepo",
  "full_name": "GeorgeCrisan/temprepo",
  "private": false,
  "owner": {
    "login": "GeorgeCrisan",
    "id": 16696844,
    "node_id": "MDQ6VXNlcjE2Njk2ODQ0",
    "avatar_url": "https://avatars2.githubusercontent.com/u/16696844?v=4",
    "gravatar_id": "",
    "url": "https://api.github.com/users/GeorgeCrisan",
    "html_url": "https://github.com/GeorgeCrisan",
    "followers_url": "https://api.github.com/users/GeorgeCrisan/followers",
    "following_url": "https://api.github.com/users/GeorgeCrisan/following{/other_user}",
    "gists_url": "https://api.github.com/users/GeorgeCrisan/gists{/gist_id}",
    "starred_url": "https://api.github.com/users/GeorgeCrisan/starred{/owner}{/repo}",
    "subscriptions_url": "https://api.github.com/users/GeorgeCrisan/subscriptions",
    "organizations_url": "https://api.github.com/users/GeorgeCrisan/orgs",
    "repos_url": "https://api.github.com/users/GeorgeCrisan/repos",
    "events_url": "https://api.github.com/users/GeorgeCrisan/events{/privacy}",
    "received_events_url": "https://api.github.com/users/GeorgeCrisan/received_events",
    "type": "User",
    "site_admin": false

 

Now you have your repository created and its time to push some content up.

 

touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:yourGitHubAccountName/repoName.git
git push -u origin master

 

Thank you!