如何使用git bash在Github上创建一个新的repo?

Jaf*_*ick 20 github github-api git-bash

如何使用git bash从我的机器创建新的存储库?

我按照以下步骤操作:

mkdir ~/Hello-World

cd ~/Hello-World

git init

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
Run Code Online (Sandbox Code Playgroud)

但是我得到了"致命的错误:你在服务器上运行了update-server-info吗?"

Kon*_*rak 23

你不能使用git bash在github上创建一个repo.Git和github是不同的东西.Github是一个平台,让你主持和协作代码,而git是使用的版本控制工具.您可以在维基百科文章中阅读更多关于它们的信息:githubgit.

但是,如果您打算使用终端创建github repo,则可以使用github api和curl来完成.


T04*_*435 7

我创建了这个bash文件来自动完成所有操作.

#!/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
Run Code Online (Sandbox Code Playgroud)

又怎样:

复制上面的代码.将其保存为NAME.sh,将其添加到PATH中.重启终端或打开一个新终端.

$ NAME newreponame
$ NAME
$ Enter Github Repository Name: 
Run Code Online (Sandbox Code Playgroud)

谢谢.


Aka*_*all 5

可能在github上创建repo的最简单方法是这行之前的某个地方:

git remote add origin https://github.com/username/Hello-World.git
Run Code Online (Sandbox Code Playgroud)

转到https://github.com/new并在github上创建一个存储库,然后运行你的最后两行,一切都应该工作.

  • 有没有办法在终端上创建一个新的仓库(在github.com上)? (5认同)