How to create a new repo at Github using git bash?

一曲冷凌霜 提交于 2019-12-02 15:38:53

You cannot create a repo on github using git bash. Git and github are different things. Github is a platform that let's you host and collaborate on code while git is the version control tool used. You can read more about them on wikipedia articles: github and git.

However if your intention is to create a github repo using terminal, you can do it using the github api and curl.

I have created this bash file to do it all automatically.

#!/bin/sh
reponame="$1"
if [ "$reponame" = "" ]; then
read -p "Enter Github Repository Name: " reponame
fi
mkdir ./$reponame
cd $reponame
curl -u USERNAME https://api.github.com/user/repos -d "{\"name\":\"$reponame\"}"
git init
echo "ADD README CONTENT" > README.md
git add README.md
git commit -m "Starting Out"
git remote add origin git@github.com:USERNAME/$reponame.git
git push -u origin master

So how:

copy the code above. save it as NAME.sh, add it to your PATH. restart terminal or open a new one.

$ NAME newreponame
$ NAME
$ Enter Github Repository Name: 

Thanks.

Probably the easiest way to create a repo on github is somewhere before this line:

git remote add origin https://github.com/username/Hello-World.git

go to https://github.com/new and create a repository on github, then run your last two lines and everything should work.

tecnocrata

First, try to do this right before the git push:

git pull repo branch

Then try to do the following:

$ git init --bare yourreponame.git

Then do what you were doing before:

touch README

git add README

git commit -m 'first commit'

git remote add origin https://github.com/username/Hello-World.git

git push origin master

I think it is doable.

You can do it using curl (if you are on Windows, you'll have to install it)

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

Make sure to replace USER and REPO with your github username and the name of the repository you want to create respectively

It asks for password, input your github admin password and you are good to go.

Actually answered by James Barnett here https://teamtreehouse.com/community/how-does-one-add-a-repository-to-github-using-git-commandline-calls-only

just try to add -u in your last line:

git push -u origin master

Maybe you are getting this error because you didn't set your identity:

$ git config --global user.name "John Doe" $ git config --global user.email johndoe@example.com

Here you can find the steps to create and put your repository on github: http://programertools.blogspot.com/2014/04/how-to-use-github.html

Read the documentation on GitHub Doc https://help.github.com/articles/create-a-repo/ They do a good job documenting it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!