[git] git push问题 解决 Updates were rejected because the tip of your current branch is behind 和每次输入用户名和密码

问题1: 当尝试push到github时 git push -u origin master 出现

error: failed to push some refs to 'git@github.com:519ebayproject/519ebayproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

原因 :远程仓库与本地有不同,需要合并(比如:在github创建仓库时初始化过了,你现在把一个本地仓库与它关联并想push,那先要和原先的github仓库合并)

解决方法

命令(假设你的远程库名字是origin)

git pull origin master

使用git pull将最新的更改从远程存储库拉到本地存储库。

问题2: git push 每次都需要输入用户名和密码

原因 : 采用的是 https 方式提交代码,创建版本库时用的

git remote add origin https://github.com/user/repo.git

解决方法 :如果采用的是 ssh 方式只需要在版本库中添加用户的 sha 的key就可以实现提交时无需输入用户名和密码。

步骤1:改用下面的创建版本库方法:

git remote add origin git@github.com:(用户名)/版本库名 

例如:

git remote add origin git@github.com:michaelliao/learngit.git

步骤2: 之后需要创建SSH Key(如果之前在github中添加过了,就可以忽略这一步),参考 廖雪峰老师

步骤3: 提交代码,已经不用登录了

git push -u origin master

posted @ 2020-01-24 13:04  conver^_^  阅读(687)  评论(0编辑  收藏  举报