git push时出现
$ git push tt ycv1
error: src refspec ycv1 does not match any
error: failed to push some refs to 'xxxx'
当将本地分支 push 到远端同名的分支时,branchname 只需要写一个分支名就可以(如直接克隆远程分支后修改再push)
但当要 push 到的远端分支名不同于本地分支名时,需要使用
git push origin [本地分支名:远端分支名]
.
但是又出现
$ git push tt master:ycv1
To https://gitee.com/...
! [rejected] master -> ycv1 (fetch first)
error: failed to push some refs to 'https://gitee.com/...'
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.
原因:其他地方向同一远端库推送了代码,导致本地不是最新的.
方法一:git pull 一下即可,如果进入MERGE_MSG(linux)界面,可以ESC+:wq退出,然后git push 远程分支(但不建议这样做)
方法二:git fetch + git merge + git push 远程分支(建议使用)
然后又使用$ git pull tt ycv1
出现fatal: refusing to merge unrelated histories
这是因为两个分支没有取得关系,
在你操作命令后面加--allow-unrelated-histories
,例如$ git pull tt ycv1 --allow-unrelated-histories
然后$ git push tt master:ycv1
成功!!