您的位置:首页 > 编程语言

github简单使用教程

2014-10-23 15:06 225 查看

1.本地Git和GitHub关联

首先在本地创建ssh key;
$ ssh-keygen -t rsa -C "your_email@youremail.com"

[/code]
后面的your_email@youremail.com改为你的邮箱,之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。
回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key。为了验证是否成功,在git bash下输入:
$ ssh -T git@github.com

[/code]
如果是第一次的会提示是否continue,输入yes就会看到:You've successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
接下来我们要做的就是把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们。
$ git config --global user.name "your name"

$ git config --global user.email "your_email@youremail.com"

[/code]
进入要上传的仓库,右键git bash,添加远程地址:
$ git remote add origin git@github.com:yourName/yourRepo.git

[/code]
后面的yourName和yourRepo表示你再github的用户名和刚才新建的仓库,加完之后进入.git,打开config,这里会多出一个remote “origin”内容,这就是刚才添加的远程地址,也可以直接修改config来配置远程地址。

2.提交、上传

接下来在本地仓库里添加一些文件,比如README,
$ git add README

$ git commit -m "first commit"

[/code]
上传到github:
$ git push origin master

[/code]
git push命令会将本地仓库推送到远程服务器。

git pull命令则相反。
错误整理:
1.Agent admitted failure to sign using the key.

Permission denied (publickey).

fatal: The remote end hung up unexpectedly

执行 ssh-add
2.ERROR: Repository not found.

fatal: The remote end hung up unexpectedly

在github上创建个版本仓库
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: