Create git repository using alias from terminal

Hi I want to create a git repository like this:

curl -u 'USER' -d '{"name":"REPO"}'


But I want to do it using an alias in terminal (Ubuntu) like

alias newRepo = curl -u 'USER' -d '{"name":"$1"}';
                git remote add origin$1.git;


So, after I type in the terminal:

newRepo test


And it creates the repo and adds the remote "origin".


source to share

3 answers

You can do it like this:

First, create a script newRepo :

if [ "$user" = "" ]; then
read -p "Enter Github username: " user
if [ "$reponame" = "" ]; then
read -p "Enter Github Repository Name: " reponame
curl -u "$user" -d "{\"name\":\"$reponame\"}"


Then make an alias:

alias newRepo=/pathtothenewReposcript


Now you can use:

newRepo username reponame


to create a new repository on github.



You can find good examples of git aliases using the shell function in Git alias to display the GitHub commit url . "

The trick is to find the correct combination of single quotes / double quotes / escape when entering the git config alias command.

In your case, given that you have a "!", You cannot surround your git config aliases parameter with double quotes if you are in bash ( no '!' In double quotes )

This leaves you with a single quote ( ) that takes ' ', and strips off the single quotes (again in bash, which would be easier in zsh): $



As an example:

vonc@bigvonc MINGW64 /c/Users/vonc
$ git config --global --replace-all alias.newrepo2 '!f() { echo \'e\'; }; f'
bash: syntax error near unexpected token `}'

vonc@bigvonc MINGW64 /c/Users/vonc
$ git config --global --replace-all alias.newrepo2 $'!f() { echo \'e\'; }; f'


Last command:

vonc@bigvonc MINGW64 /c/Users/vonc
$ git config --global --replace-all alias.newrepo $'!f() { curl -u \'USER\' -d \'{"name":"$1"}\'; git remote add origin$1.git; }; f'


In this case, if you typed curl -u 'USER' -d '{"name":"xxx"}'

, he will ask for a password for " USER


It means:

  • maybe ' USER

    ' shoud be$(whoami)

  • and ... a git config

    multiple command alias doesn't seem to support waiting for an argument to be entered into stdin ...


You cannot pass parameters to aliases. Create a bash function.



All Articles