git及github使用

1、生成ssh公钥

ssh-keygen -t rsa -C "[email protected]"

2、添加公钥到git仓库

就是将在用户主目录中.ssh文件夹下的id_rsa.pub文件中内容上传到git仓库

对于github仓库,打开github,找到账户里面添加SSH,把idrsa.pub内容复制到key里面

3、测试是否生效

这里连接github,使用命令:ssh -T [email protected]

4、连接成功后,下载库到本地

git clone git://github.com/{yourname}/{yourRep}.git

5、本地修改代码后提交

当前在master上:git push origin master

会出现如下错误:

fatal: remote error:

  You can't push to git://github.com/{yourname}/{yourRep}.git

  Use https://github.com/{yourname}/{yourRep}.git

解决方法:

git remote rm origin

git remote add origin [email protected]:{yourname}/{yourRep}.git

6.迁移git服务器

git commit -m "Change repo." # 先把所有为保存的修改打包为一个commit
git remote remove origin # 删掉原来git源
git remote add origin [YOUR NEW .GIT URL] # 将新源地址写入本地版本库配置文件
git push -u origin master # 提交所有代码

猜你喜欢

转载自wangzt-2008.iteye.com/blog/1922395