git使用遇到的问题

1、上传ssh时,服务器验证不过:

如果电脑上有ssh key,要将就有的备份并删除(直接删除文件即可),如果没有,输入以下命令:

1 $ ssh-keygen -t rsa -C "邮件地址@youremail.com"
2 Generating public/private rsa key pair. 3 Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<回车就好>

尤其注意第三行,应该直接回车,而不是输入自定义的文件名。然后将生成的id_rsa.pub的内容原封不动上传到git,之后测试命令:

1 ssh -T git@github.com

选择“yes”,输入用户名和密码,提示成功!

2、error: failed to push some refs to ‘https://github.com/

git push代码时需要将远程仓库的文件拉下来(pull)然后push上去。

git的本地仓库由git维护的三棵树组成,第一棵是我的工作目录,它持有实际文件,第二棵是缓冲区(Index),保存临时改动,第三棵是head,指向最后提交后的结果。

1 git add <filename>

是将文件提交到缓存区,应该是“计划改动”,然后实际提交改动:

git commit -m "代码提交信息"

这时候改动已经提交到head,但是还没有到达远程仓库,调用:

1 git push origin master

则是将改动提交到远程仓库,如果还没有克隆现有仓库,并欲将仓库连接到某个远程服务器,可以使用如下命令添加:

git remote add origin <server>

错误:

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


解决办法:

Elvis@ELVIS-PC /f/gitrepo/TestJedis (master) $ git remote add origin git@gitserver:TestRedis.git Elvis@ELVIS-PC /f/gitrepo/TestJedis (master) $ git push origin master ssh: gitserver: no address associated with name fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. Elvis@ELVIS-PC /f/gitrepo/TestJedis (master) $ git remote set-url origin git@github.com:afredlyj/TestRedis.git Elvis@ELVIS-PC /f/gitrepo/TestJedis (master) $ git push origin master Enter passphrase for key '/c/Users/Elvis/.ssh/id_rsa': Counting objects: 8, done. Delta compression using up to 2 threads. Compressing objects: 100% (7/7), done. Writing objects: 100% (7/7), 2.07 KiB, done. Total 7 (delta 2), reused 0 (delta 0) To git@github.com:afredlyj/TestRedis.git 7bcfb1a..b02a2fe master -> master Elvis@ELVIS-PC /f/gitrepo/TestJedis (master)

借鉴地址:http://stackoverflow.com/questions/3283717/github-no-address-associated-with-name

参考资料:

    原文作者:leealways87
    原文地址: https://www.cnblogs.com/leealways87/archive/2013/04/14/3020840.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞