By anddoutoi


2010-03-11 09:25:00 8 Comments

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 repo and push my commit to GitHub from here? I know it's no big deal to just fire up a browser and head over to Create a New Repository, but if there is a way to achieve this from the CLI I would be happy.

I read a vast amount of articles but none that I found mention how to create a remote repo from the CLI using git commands. Tim Lucas's nice article Setting up a new remote git repository is the closest I found, but GitHub does not provide shell access.

24 comments

@Gabriele B 2020-10-19 07:47:39

Both the accepted answer and the most-voted answer so far are now outdated. Password authentication is deprecated and it will be removed on November 13, 2020 at 16:00 UTC.

The way to use GitHub API now is via personal access tokens.

You need to (replace ALL CAPS keywords):

  1. Create a personal access token via the website. Yes, you have to use the browser, but it is only once for all future accesses. Store the token securely.
  2. Create the repo via
curl -H 'Authorization: token MY_ACCESS_TOKEN' https://api.github.com/user/repos  -d '{"name":"REPO"}'

or, to make it private from the start:

curl -H 'Authorization: token MY_ACCESS_TOKEN' https://api.github.com/user/repos -d '{"name":"REPO", "private":"true"}'
  1. Add the new origin and push to it:
git remote add origin [email protected]:USER/REPO.git
git push origin master

This has the disadvantage that you have to type the token each time, and that it appears in your bash history.

To avoid this, you can

  1. Store the header in a file (let's call it, say, HEADER_FILE)
Authorization: token MY_ACCESS_TOKEN
  1. Have curl read from the file
curl -H @HEADER_FILE https://api.github.com/user/repos -d '{"name":"REPO"}' # public repo
curl -H @HEADER_FILE https://api.github.com/user/repos -d '{"name":"REPO", "private":"true"}' # private repo
  1. To make things more secure, you could set access permissions to 400 and the user to root
chmod 400 HEADER_FILE
sudo chown root:root HEADER_FILE
  1. Now sudo will be needed to access the header file
sudo curl -H @HEADER_FILE https://api.github.com/user/repos -d '{"name":"REPO"}' # public repo
sudo curl -H @HEADER_FILE https://api.github.com/user/repos -d '{"name":"REPO", "private":"true"}' # private repo

@Bala.Raj 2020-09-21 03:46:33

Finally, it happened GitHub has officially announced their new CLI for all the core features.

check here: https://cli.github.com/

To install via HomeBrew: brew install gh for other Ways : https://github.com/cli/cli#installation

then

gh repo create

Other available features.

$ gh --help

Work seamlessly with GitHub from the command line.

USAGE
  gh <command> <subcommand> [flags]

CORE COMMANDS
  gist:       Create gists
  issue:      Manage issues
  pr:         Manage pull requests
  release:    Manage GitHub releases
  repo:       Create, clone, fork, and view repositories

ADDITIONAL COMMANDS
  alias:      Create command shortcuts
  api:        Make an authenticated GitHub API request
  auth:       Login, logout, and refresh your authentication
  completion: Generate shell completion scripts
  config:     Manage configuration for gh
  help:       Help about any command

FLAGS
  --help      Show help for command
  --version   Show gh version

EXAMPLES
  $ gh issue create
  $ gh repo clone cli/cli
  $ gh pr checkout 321

ENVIRONMENT VARIABLES
  See 'gh help environment' for the list of supported environment variables.

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

FEEDBACK
  Open an issue using 'gh issue create -R cli/cli'

So now you can create repo from your terminal.

@cnvzmxcvmcx 2014-03-24 07:50:02

Update 20200714

Github has a new official CLI.

...gh is a new project that helps us explore what an official GitHub CLI tool can look like with a fundamentally different design. While both tools bring GitHub to the terminal, hub behaves as a proxy to git, and gh is a standalone tool.

The core difference from hub is that this does not wrap over existing git commands. So, you can not alias git to gh like you can with hub.

We didn't add it to hub because we decided to design GitHub CLI differently than being a git wrapper, i.e. as its own command. It turns out, maintaining an executable that's a proxy to git is hard to maintain, and also we didn't want to be limited by having to always keep git compatibility. We didn't want to build GitHub CLI on a paradigm that is brittle from the start.

-- mislav (Maintainer of hub)

Original answer

What you need is hub. Hub is a command-line wrapper for git. It has been made to integrate with native git using alias. It tries to provide github actions into git including creating new repository.

→  create a repo for a new project
$ git init
$ git add . && git commit -m "It begins."
$ git create -d "My new thing"
→  (creates a new project on GitHub with the name of current directory)
$ git push origin master

@Xavier Guihot 2020-04-27 13:37:51

With Github's official new command line interface:

gh repo create

See additional details and options and installation instructions.


For instance, to complete your git workflow:

mkdir project
cd project
git init
touch file
git add file
git commit -m 'Initial commit'
gh repo create
git push -u origin master

@Chris Stryczynski 2018-01-07 16:31:04

Disclamier: I'm the author of the open source project

This functionality is supported by: https://github.com/chrissound/Human-Friendly-Commands essentially it is this script:

#!/usr/bin/env bash

# Create a repo named by the current directory
# Accepts 1 STRING parameter for the repo description
# Depends on bin: jq
# Depends on env: GITHUB_USER, GITHUB_API_TOKEN
github_createRepo() {
  projName="$(basename "$PWD")"
  json=$(jq -n \
    --arg name "$projName" \
    --arg description "$1" \
    '{"name":$name, "description":$description}')

  curl -u "$GITHUB_USER":"$GITHUB_API_TOKEN" https://api.github.com/user/repos -d "$json"
  git init
  git remote add origin [email protected]:"$GITHUB_USER"/"$projName".git
  git push origin master
};

@not2qubit 2018-11-25 15:06:01

This is indeed the new way for using a GitHub Personal Access Token. (The old way of adding it via ?access_token=${ACCESSTOKEN} no longer works.

@Joshua Dance 2017-09-22 17:03:34

Found this solution which I liked: https://medium.com/@jakehasler/how-to-create-a-remote-git-repo-from-the-command-line-2d6857f49564

You first need to create a Github Personal Access Token

Open up your ~/.bash_profile or ~/.bashrc in your favorite text editor. Add the following line near the top of your file, where the rest of the export ‘ed variables are:

export GITHUB_API_TOKEN=<your-token-here>

Somewhere below, by your other bash functions, you can paste something similar to the following:

function new-git() {
    curl -X POST https://api.github.com/user/repos -u <your-username>:$GITHUB_API_TOKEN -d '{"name":"'$1'"}'
}

Now, whenever you’re creating a new project, you can run the command $ new-git awesome-repo to create a new public remote repository on your Github user account.

@Arpit Aggarwal 2017-02-03 17:09:23

Nope, you have to open a browser atleast once to create your username on GitHub, once created, you can leverage GitHub API to create repositories from command line, following below command:

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

For example:

curl -u 'arpitaggarwal' https://api.github.com/user/repos -d '{"name":"command-line-repo"}'

@SherylHohman 2018-02-26 01:42:39

Then git remote add origin https://github.com/github-username/repo-name.git to link your local project to github. For the example, the command would look like this: git remote add origin https://github.com/arpitaggarwal/command-line-repo.git

@quine 2016-12-19 09:43:29

For all the Python 2.7.* users. There is a Python wrapper around the Github API that is currently on Version 3, called GitPython. Simply install using easy_install PyGithub or pip install PyGithub.

from github import Github
g = Github(your-email-addr, your-passwd)
repo = g.get_user().user.create_repo("your-new-repos-name")

# Make use of Repository object (repo)

The Repository object docs are here.

@Pavan 2016-07-08 11:17:27

create a new repository on the command line

echo "# <RepositoryName>" >> README.md

git init

git add README.md

git commit -m "first commit"

git remote add origin https://github.com/**<gituserID>/<RepositoryName>**.git

git push -u origin master

push an existing repository from the command line

git remote add origin https://github.com/**<gituserID>/<RepositoryName>**.git

git push -u origin master

@Matthew Read 2016-09-23 19:55:23

This does not work; it doesn't create the remote repository.

@mipadi 2010-03-11 14:20:42

You can create a GitHub repo via the command line using the GitHub API. Check out the repository API. If you scroll down about a third of the way, you'll see a section entitled "Create" that explains how to create a repo via the API (right above that is a section that explains how to fork a repo with the API, too). Obviously you can't use git to do this, but you can do it via the command line with a tool like curl.

Outside of the API, there's no way to create a repo on GitHub via the command line. As you noted, GitHub doesn't allow shell access, etc., so aside from the GitHub API, the only way to create a repo is through GitHub's web interface.

@anddoutoi 2010-03-11 20:58:41

Thanks a bunch mipadi! Didn´t know about the GitHub API. For everyone else with the same problem, this is what i basicly did: curl -F 'login=username' -F 'token=API Token' https://github.com/api/v2/yaml/repos/create -F name=reponame. Your API Token can be found on the GitHub site, click Account Settings, look for Administrative Information and API Token (32 character long string).

@Joachim Breitner 2012-06-13 17:49:08

It seems this is out of date, at least I do not find the API Token there.

@anddoutoi 2012-06-27 19:32:09

Yes, version 2 of the API is marked as obsolete and they want us to use version 3. I havn´t yet grokked v3 but when I get the time I will try to wrap my head around it.

@JiminyCricket 2012-08-23 08:36:28

API Version 3 Syntax given below via @bennedich stackoverflow.com/a/10325316/305633

@cseder 2014-02-02 02:33:11

Guess sometimes people have to agree to disagree. If you have Github set up with the proper security configuration and certificates, using a transport layer security model, you should not have to use the API to create a new repo. Mark my words should. If it is like that it is not a good implementation. I've switched from Github to Mercurial. If you get to choose between MacGyver and James Bond, choose the latter!

@mipadi 2014-02-02 09:12:13

@cseder: Git doesn't require this to create a repo, but setting up one on GitHub does. I don't think Mercurial lets you create a repo on a remote server by pushing to a nonexistent repo, either.

@cseder 2014-02-04 22:23:25

No, it works in a slightly different manner. My point isn't to push code to a non-existing repo. What would be the point of trying to do so? I'm talking about initializing and committing from the command-line as the question was all about. Quote: Is there any git command to create a new remote repo and push my commit to GitHub from here? Roger Out.

@mipadi 2014-02-04 22:28:00

@cseder: The question is asking if it's possible to create a remote repo on GitHub via the GitHub API, not how to create a new repo and push to an existing one on GitHub.

@cseder 2014-02-04 22:31:40

@mipadi Ok. Misunderstood then. That happens to me sometimes. I'm human I think...

@John Strood 2016-07-18 12:34:39

@mipadi Sorry for sounding like a newbie, but what do you mean by Obviously you can't use git to do this? It isn't so obvious to me, if you could help explain...

@Bodo Thiesen 2017-05-24 04:37:48

@JohnStrood: It is a well known fact, that you can't create a remote repo using git init --remote or something like that. You will have to go to the remote host, create the repo there using git init and then you can push to that (assuming you have all necessary access rights). Obviously, you can't do that without shell access (that github doesn't provide) so you have to use other means to create the github repo - here: Use the API that github provides, which obviously is not part of the git protocol. That's what @mipadi meant, when he said, Obviously you can't use git to do this.

@kenorb 2015-08-03 19:13:19

Simple steps (using git + hub => GitHub):

  1. Install Hub (GitHub).

    • OS X: brew install hub
    • having Go: go get github.com/github/hub
    • otherwise (having Go as well):

      git clone https://github.com/github/hub.git && cd hub && ./script/build
      
  2. Go to your repo or create empty one: mkdir foo && cd foo && git init.

  3. Run: hub create, it'll ask you about GitHub credentials for the first time.

    Usage: hub create [-p] [-d DESCRIPTION] [-h HOMEPAGE] [NAME]

    Example: hub create -d Description -h example.com org_name/foo_repo

    Hub will prompt for GitHub username & password the first time it needs to access the API and exchange it for an OAuth token, which it saves in ~/.config/hub.

    To explicitly name the new repository, pass in NAME, optionally in ORGANIZATION/NAME form to create under an organization you're a member of.

    With -p, create a private repository, and with -d and -h set the repository's description and homepage URL, respectively.

    To avoid being prompted, use GITHUB_USER and GITHUB_PASSWORD environment variables.

  4. Then commit and push as usual or check hub commit/hub push.

For more help, run: hub help.

See also: Importing a Git repository using the command line at GitHub.

@Kasper 2015-09-30 12:44:37

How can I set GITHUB_USER and GITHUB_PASSWORD environment variables ?

@kenorb 2015-09-30 12:57:23

Probably you can export them, see: GH #245.

@tiktak 2018-03-22 00:25:25

Worked great for me, note "hub" is also available on MacPorts.

@Tᴀʀᴇǫ Mᴀʜᴍᴏᴏᴅ 2020-04-09 18:33:14

I think this is what I was looking for! :)

@robru 2015-03-08 07:19:46

Based on the other answer by @Mechanical Snail, except without the use of python, which I found to be wildly overkill. Add this to your ~/.gitconfig:

[github]
    user = "your-name-here"
[alias]
    hub-new-repo = "!REPO=$(basename $PWD) GHUSER=$(git config --get github.user); curl -u $GHUSER https://api.github.com/user/repos -d {\\\"name\\\":\\\"$REPO\\\"} --fail; git remote add origin [email protected]:$GHUSER/$REPO.git; git push origin master"

@daveloyall 2016-08-03 17:14:36

I love this alias. Thanks again, @Robru. P.S. if this doesn't work, or stops working after a fresh OS install.. make sure you have curl installed!

@Nasif Md. Tanjim 2015-01-05 05:53:15

To Quickly Create the Remote Repository by Using a Bash Shell

It is cumbersome to type the complete code every time a repository is to be created

curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}' git remote add origin [email protected]:USER/REPO.git git push origin master

An easier approach is:

  1. create a shell script in a directory i.e. /home/USER_NAME/Desktop/my_scripts named githubscript.sh
  2. Modify and save the following code to the githubscript.sh file
#!bin/bash
curl -u 'YOUR_GITHUB_USER_NAME' https://api.github.com/user/repos -d "{\"name\":\"$1\"}";
git init;
git remote add origin [email protected]:YOUR_GITHUB_USER_NAME/$1.git;

N.B. Here $1 is the repository name that is passed as an argument when invoking the script Change YOUR_GITHUB_USER_NAME before saving the script.

  1. Set required permissions to the script file chmod 755 githubscript.sh

  2. Include the scripts directory in the environment configuration file. nano ~/.profile; export PATH="$PATH:$HOME/Desktop/my_scripts"

  3. Also set an alias to run the githubscript.sh file. nano ~/.bashrc; alias githubrepo="bash githubscript.sh"

  4. Now reload the .bashrc and .profile files in the terminal. source ~/.bashrc ~/.profile;

  5. Now to create a new repository i.e. demo: githubrepo demo;

@Damiii 2016-02-15 18:19:14

In your code, I changed this part: git remote add origin [email protected]:YOUR_GITHUB_USER_NAME/$1.git; to git remote add origin https://github.com/YOUR_GITHUB_USER_NAME/$1.git; For users, who don't use SSH key.

@traycerb 2014-09-23 04:59:51

For rep reasons, I can't add this as a comment (where it would better go with bennedich's answer), but for Windows command line, here is the correct syntax:

curl -u YOUR_USERNAME https://api.github.com/user/repos -d "{\"name\":\"YOUR_REPO_NAME\"}"

It's the same basic form, but you have to use double quotes (") instead of single, and escape the double quotes sent in the POST parameters (after the -d flag) with backslashes. I also removed the single quotes around my username, but if your username had a space (possible?) it would probably need double quotes.

@mklement0 2015-05-29 16:53:06

Good to know for Windows users. No, usernames cannot contain spaces (The sign-up form at github.com states: "Username may only contain alphanumeric characters or single hyphens, and cannot begin or end with a hyphen"). Thus, no double-quoting of the username needed.

@JuliandotNut 2016-05-18 08:07:31

Github power shell does not accept -u with curl, on Windows :(

@T.Todua 2014-04-28 14:38:47

here is my initial git commands (possibly, this action takes place in C:/Documents and Settings/your_username/):

mkdir ~/Hello-World
# Creates a directory for your project called "Hello-World" in your user directory
cd ~/Hello-World
# Changes the current working directory to your newly created directory
touch blabla.html
# create a file, named blabla.html
git init
# Sets up the necessary Git files
git add blabla.html
# Stages your blabla.html file, adding it to the list of files to be committed
git commit -m 'first committttt'
# Commits your files, adding the message 
git remote add origin https://github.com/username/Hello-World.git
# Creates a remote named "origin" pointing at your GitHub repository
git push -u origin master
# Sends your commits in the "master" branch to GitHub

@JuliandotNut 2016-05-18 08:10:07

Hello-World repo should be available at GitHub in this case, does not address the problem in the question.

@Benjamin Dunphy 2014-04-24 00:26:55

For Rubyists:

gem install githubrepo
githubrepo create *reponame*

enter username and pw as prompted

git remote add origin *ctrl v*
git push origin master

Source: Elikem Adadevoh

@Nay 2011-09-27 03:14:13

This can be done with three commands:

curl -u 'nyeates' https://api.github.com/user/repos -d '{"name":"projectname","description":"This project is a test"}'
git remote add origin [email protected]:nyeates/projectname.git
git push origin master

(updated for v3 Github API)


Explanation of these commands...

Create github repo

    curl -u 'nyeates' https://api.github.com/user/repos -d '{"name":"projectname","description":"This project is a test"}'
  • curl is a unix command (above works on mac too) that retrieves and interacts with URLs. It is commonly already installed.
  • "-u" is a curl parameter that specifies the user name and password to use for server authentication.
    • If you just give the user name (as shown in example above) curl will prompt for a password.
    • If you do not want to have to type in the password, see githubs api documentation on Authentication
  • "-d" is a curl parameter that allows you to send POST data with the request
  • "name" is the only POST data required; I like to also include "description"
  • I found that it was good to quote all POST data with single quotes ' '

Define where to push to

git remote add origin [email protected]:nyeates/projectname.git
  • add definition for location and existance of connected (remote) repo on github
  • "origin" is a default name used by git for where the source came from
    • technically didnt come from github, but now the github repo will be the source of record
  • "[email protected]:nyeates" is a ssh connection that assumes you have already setup a trusted ssh keypair with github.

Push local repo to github

git push origin master
  • push to the origin remote (github) from the master local branch

@user886596 2013-12-15 19:27:32

For users with two-factor authentication, you can use bennedich's solution, but you just need to add the X-Github-OTP header for the first command. Replace CODE with the code that you get from the two-factor authentication provider. Replace USER and REPO with the username and name of the repository, as you would in his solution.

curl -u 'USER' -H "X-GitHub-OTP: CODE" -d '{"name":"REPO"}' https://api.github.com/user/repos
git remote add origin [email protected]:USER/REPO.git
git push origin master

@bennedich 2012-04-25 23:38:57

CLI commands 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 [email protected]:USER/REPO.git
git push origin master

@ivanzoid 2012-12-01 14:31:50

The slight problem with first command is that you are leaving your GitHub password in your ~/.bash_history. I would suggest replace -u 'USER:PASS' with -u 'USER', then curl will ask you for password interactively.

@Joe Fletcher 2013-03-21 04:05:07

To make the repo private from the start, use: curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO", "private":"true"}'

@RobW 2013-04-21 20:35:10

I wrote a bash script to save us all some typing. Takes user input and has sensible defaults: gist.github.com/robwierzbowski/5430952

@Mechanical snail 2013-05-27 04:06:12

@Robin Winslow 2013-06-07 15:53:34

Here's how to add it as a git alias: git config --global alias.gh-create '!sh -c "curl -u \"USERNAME\" https://api.github.com/user/repos -d \"{\\\"name\\\":\\\"$1\\\"}\"" -'

@Robin Winslow 2013-06-13 08:42:39

Actually @MattTagg's comment below is now my preferred solution - Hub is a brilliant project for managing all sorts of GitHub actions on the command-line.

@Stuart R. Jefferys 2013-07-29 17:57:41

If using an org account, need to change the curl command to use .../orgs/ORGNAME/repos instead of .../user/repos, like curl -u 'USER' https://api.github.com/orgs/ORGNAME/repos -d '{"name":"REPO"}'

@Ionică Bizău 2014-05-28 08:17:37

Don't forget that you can generate an access token and use it this way: curl https://api.github.com/user/repos?access_token=myAccessToken -d '{"name":"REPO"}'. :-)

@Kai Carver 2015-10-18 11:57:38

oddly git remote add origin [email protected]:USER/REPO.git (SSH URL) did not work for me, but the HTTPS URL form does: git remote add origin https://github.com/USER/REPO.git

@Jared Beach 2017-01-21 18:12:49

powershell script (I have curl as an alias for cygwin's curl and $ghUsername predefined in my profile) function gh-create { $repoName = $args[0]; $data = @{ name=$repoName }; $data | ConvertTo-Json -Compress | curl -H "Content-Type: application/json" -u $ghUsername https://api.github.com/user/repos -d "@-" }

@holdenlee 2017-08-06 16:13:13

@IonicăBizău I'm getting { "message": "Not Found", "documentation_url": "https://developer.github.com/v3" } from your command.

@Arthur 2018-04-17 14:43:30

Better yet, store your credentials in a local file which you keep secure like your ssh key. Then write a script that reads the credentials and issues the curl command.

@Gabriele B 2020-10-19 07:54:02

For the record, this answer is outdated: password authentication is deprecated and will be removed soon. I have posted the a new procedure here: stackoverflow.com/a/64423133/12175820

@Mechanical snail 2013-05-27 04:03:38

I've created a Git alias to do this, based on Bennedich's answer. Add the following to your ~/.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\", \"[email protected]:{0}/{1}.git\".format(user, repo)]); check_call([\"git\", \"push\", \"origin\", \"master\"])'"

To use it, run

$ git hub-new-repo

from anywhere inside the local repository, and enter your Github password when prompted.

@adamwong246 2013-12-28 03:46:29

This did not work for me. It returns 'No such file or directory'

@Da Frenk 2014-01-15 17:45:47

This did not work for me either. It returns curl: (22) The requested URL returned error: 401 Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/lib64/python3.2/subprocess.py", line 488, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['curl', '-u', 'myusername', 'https://api.github.com/user/repos', '-d', '{"name": "reponame"}', '--fail']' returned non-zero exit status 22

@robru 2015-03-08 07:20:43

The use of python is a bit much and adds a lot of noise in the form of extra backslashes and other puncutation. I made a version with just bash: stackoverflow.com/a/28924077/1423157

@D.Deriso 2013-02-02 20:19:38

I wrote a nifty script for this called Gitter using the REST APIs for GitHub and BitBucket:

https://github.com/dderiso/gitter

BitBucket:

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 = name the repo
  • -l = (optional) set the language of the app in the repo

@cavalcade 2012-11-13 18:20:58

If you install defunkt's excellent Hub tool, then this becomes as easy as

git create

In the words of the author, "hub is a command-line wrapper for git that makes you better at GitHub."

@Alex Gray 2014-04-08 18:12:24

I LOVE hub! Also useful, is the hub - or as hub is usually aliases to git... git fork, which creates a fork of the repo for the pwd of a cloned repo that you are in... Yay.

@Dorian 2014-08-17 17:27:22

this tool is awesome! It takes care of storing your authentication token for you so you don't have to type your password over and over. Also checkout the ZSH plugin for github.

@reubano 2012-10-04 14:33:05

For directions on creating a token, go here This is the command you will type (as of the date of this answer. (replace all CAPS keywords):

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

Once you enter your password you will see the following which contains your 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 revoke your token anytime by going here

@Jason Marcell 2011-04-08 04:36:41

There is an official github gem which, I think, does this. I'll try to add more information as I learn, but I'm only just now discovering this gem, so I don't know much yet.

UPDATE: After setting my API key, I am able to create a new repo on github via the create command, however I am not able to use the create-from-local command, which is supposed to take the current local repo and make a corresponding remote out on github.

$ gh create-from-local
=> error creating repository

If anyone has some insight on this, I'd love to know what I'm doing wrong. There's already an issue filed.

UPDATE: I did eventually get this to work. I'm not exactly sure how to re-produce the issue, but I just started from scratch (deleted the .git folder)

git init
git add .emacs
git commit -a -m "adding emacs"

Now this line will create the remote repo and even push to it, but unfortunately I don't think I can specify the name of the repo I'd like. I wanted it to be called "dotfiles" out on github, but the gh gem just used the name of the current folder, which was "jason" since I was in my home folder. (I added a ticket asking for the desired behavior)

gh create-from-local

This command, on the other hand, does accept an argument to specify the name of the remote repo, but it's intended for starting a new project from scratch, i.e. after you call this command, you get a new remote repo that's tracking a local repo in a newly-created subfolder relative to your current position, both with the name specified as the argument.

gh create dotfiles

@jameshfisher 2013-12-26 00:23:40

This project hasn't had any work on it for a couple of years, didn't work for me, and, as implied here, is dead. It has apparently been replaced by the hub tool, as suggested in this answer.

Related Questions

Sponsored Content

14 Answered Questions

[SOLVED] How to change the remote a branch is tracking?

  • 2011-02-02 18:20:33
  • joachim
  • 449136 View
  • 711 Score
  • 14 Answer
  • Tags:   git

16 Answered Questions

[SOLVED] Make the current commit the only (initial) commit in a Git repository?

35 Answered Questions

[SOLVED] Download a single folder or directory from a GitHub repo

7 Answered Questions

[SOLVED] How to rebase local branch with remote master

13 Answered Questions

[SOLVED] There is no tracking information for the current branch

  • 2015-08-17 17:27:05
  • valerio0999
  • 477752 View
  • 625 Score
  • 13 Answer
  • Tags:   git github git-pull

9 Answered Questions

[SOLVED] git - remote add origin vs remote set-url origin

  • 2017-03-16 09:53:18
  • Irbis
  • 565449 View
  • 460 Score
  • 9 Answer
  • Tags:   git github

4 Answered Questions

[SOLVED] Undo a particular commit in Git that's been pushed to remote repos

6 Answered Questions

[SOLVED] How can I rollback a github repository to a specific commit?

  • 2010-12-07 00:51:00
  • Jonathan Vanasco
  • 373449 View
  • 447 Score
  • 6 Answer
  • Tags:   git github

26 Answered Questions

[SOLVED] How can I reconcile detached HEAD with master/origin?

  • 2011-04-24 17:51:01
  • Ben Zotto
  • 1007003 View
  • 1590 Score
  • 26 Answer
  • Tags:   git

37 Answered Questions

[SOLVED] Git for beginners: The definitive practical guide

  • 2008-11-24 23:50:29
  • Adam Davis
  • 708670 View
  • 854 Score
  • 37 Answer
  • Tags:   git version-control

Sponsored Content