image.png
用 Github 有一两年了, 是时候总结一下以前踩得坑了, 这些坑开始时还真把自己摔得不轻!!!!!
小插曲: 自己以前用 hexo 搭建的博客, 每次写博客都要新建. md 文件等初始化步骤, 然后提交, 有些繁琐, 再加上自己又换了台电脑, 又要部署 hexo(虽然不需要重新部署), 但还是有些步骤, 索性用简书写, 方便快捷些!
git pull 时
- ssh: Could not resolve hostname github.com: Name or service not known, fatal: Could not read from remote repository.
- $ git pull
- ssh: Could not resolve hostname github.com: Name or service not known
- fatal: Could not read from remote repository.
- Please make sure you have the correct access rights
- and the repository exists.
这个错误好醉, 是因为没网了, 就很皮
git 本地仓库首次 push 到远程仓库出现错误 ! [rejected] master -> master (fetch first)
新建好本地的仓库和远程仓库之后,
经过
git add .
然后
git commit - m "......"
最后想推送到远程仓库的时候
git push - u origin master
出现下图错误
image.png
解决很简单, 使用强制推送
使用下面的命令
git push - f origin master
附上 git push 的说明
- NAME
- git-push - Update remote refs along with associated objects
- SYNOPSIS
- git push [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
- [--repo=<repository>] [-f | --force] [--prune] [-v | --verbose]
- [-u | --set-upstream]
- [--[no-]signed|--sign=(true|false|if-asked)]
- [--force-with-lease[=<refname>[:<expect>]]]
- [--no-verify] [<repository> [<refspec>]]
- -f --force
- Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. Also, when --force-with-lease option is used, the command refuses to update a remote ref whose current value does not match what is expected.
- This flag disables these checks, and can cause the remote repository to lose commits; use it with care.
- Note that --force applies to all the refs that are pushed, hence using it with push.default set to matching or with multiple push destinations configured with remote.*.push may overwrite refs other than the current branch (including local refs that are strictly behind their remote counterpart). To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch). See the<refspec>... section above for details.
github 上传时出现 error: src refspec master does not match any
如下:
image.png
引起该错误的原因是, 目录中没有文件, 空目录是不能提交上去的
解决方法: 先提交文件
git add.git commit - m ""
例如下:
- touch README
- git add README
- git commit -m 'first commit'
- git push origin master
- fatal: unable to create '../../.git/index.lock':File exists
mark
解决方法: 把文件 index.lock 删掉
- Permission denied (publickey).
- fatal: The remote end hung up unexpectedly
错误原因: github 上没有配置公钥
解决方法: 配置公钥, 并放到 github 上
GitHub 设置公钥在 windows 下面
安装 git, 从程序目录打开 "Git Bash"
键入命令: ssh-keygen -t rsa -C "email@email.com"
"email@email.com" 是 github 账号
提醒你输入 key 的名称, 输入如 id_rsa
如果执行成功返回
- Generating public/private rsa key pair.
- Enter file in which to save the key (/home/forwhat.cn/.ssh/id_rsa):
在这里就是设置存储地址了. 反正我是直接按的回车, 一直回车
在 C:\Documents and Settings\Administrator \ 下产生两个文件: id_rsa 和 id_rsa.pub
把 4 中生成的密钥文件复制到 C:\Documents and Settings\Administrator.ssh\ 目 录下
用记事本打开 id_rsa.pub 文件, 复制内容, 在 github.com 的网站上到 ssh 密钥管理页面, 添加新公钥, 随便取个名字例如你的电脑名
需要注意步骤 2 中产生的密钥文件在当前用户的根目录, 必须把这两个文件放到当前用户目录的. ssh 目录下才能生效
- ------------2017 / 8 / 14 There is no tracking information
- for the current branch.Please specify which branch you want to merge with.
mark
是因为本地分支和远程分支没有建立联系 (使用 git branch -vv 可以查看本地分支和远程分支的关联关系) . 根据命令行提示只需要执行以下命令即可
如果不想新建分支
git branch--set - upstream master origin / master
如果想新建分支
git branch--set - upstream - to = origin / 远程分支的名字本地分支的名字
git branchset - upstream - to = origin / develop develop
或
git branch--set - upstream develop origin / develop
(develop 为新建分支 name)
同时推荐大家看一下下面这篇 -- 创建于合并分支 https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001375840038939c291467cc7c747b1810aab2fb8863508000
坑不会踩完的, 但会一直进步着, 大家加油......
来源: http://www.jianshu.com/p/f98550587b9a