<
使用git命令ssh提交项目到github
>
上一篇

修改远程仓库地址
下一篇

使用git命令https提交项目到github

使用git命令SSH提交项目到github


打开 Git Bash,开始键入各种配置信息:

git config --global user.name "You Name"
git config --global user.email yourmail@server.com

这里的配置信息中的用户名和用户邮箱,在后面 GitHub 中会用到,尽力准确配置,不要用 test or test@mail.com 等等的测试数据去配置。

创建 GitHub SSH密匙,Git Bash 下键入命令:

ssh-keygen -C 'yourmail@server.com' -t rsa

生成密钥的时候使用默认的路径就行了,密码自己设定。

然后会在 C:User你的windows用户名.ssh 下找到 id_rsa.pub 文件

笔者操作系统 windows 7 英文版,其他版本的 windows 系统可能路径略有不同。

.ssh 文件夹下同时有 id_rsa 和 id_rsa.pub 文件(注意在开启后缀名的情况下),id_rsa 是置于本地机器的密钥,用于匹配置于服务器端的密钥文件 id_rsa.pub,这样才能建立 SSH 连接。

回到 GitHub 个人首页,

测试与 GitHub 是否连接成功:SSH -v git@github.com

在 GitHub 上 添加一个 Git 仓库test ,配置项目名称和相关信息。

如何在 GitHub 上添加 Git 仓库参见: http://help.github.com/create-a-repo/

本地项目文件,在项目路径下进入 Bash 键入以下代码: (先add再commit和push)

git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:youusername/test.git
git push -u origin master

推送成功后,就可以在 GitHub 上看到 push 上去的项目文件了。

Top
Foot