今天使用androidstudio将做了一段时间的小项目上传到git。
在android studio中创建仓库,然后进入文件夹。命令行中
git remote add ###添加远程仓库
然后add
commit
push(如果忘了add commit直接push也是会报错的。)
然后
git push -u origin master
提示下面错误:
--ssh: Could not resolve hostname ssh.github.com: Name or service not known
我查看了一下配置。也没有什么问题。后来思考了一下,无法解析很有可能是dns解析的问题
看了一下我的dns原来是服务器课程设计时配置为固定的虚拟机dns解析 ip忘记改回来。
这边改为自动获取就可以了。
但是却又出现了新的报错:
error: failed to push some refs to 'git@git.oschina.net:ningbo1222/CollegeLife.g it'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
对于这个问题,很明显提示需要pull一下,
通过查询
可以通过如下命令进行代码合并【注:pull=fetch+merge]
git pull --rebase origin master
执行后在执行push,果然成功了。