git添加本地仓库和远程仓库关联,提交代码报错There is no tracking information for the current branch

  • Post author:
  • Post category:其他

github添加本地初始化仓库和远程仓库关联

git remote add origin git@xxx.git

添加完成之后,接着开始提交push代码,然后报错,要设置push的代码流向,到远程分支的哪个分支

git push --set-upstream origin master

发现报错了,

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@xxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

说是你当前分支在远程分支之前,所以还是需要再pull一下。但是又报下面的错误,不相关代码无法拉取做合并。

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:
Merge branch 'master' of github.com:xxx

    git branch --set-upstream-to=origin/<branch> master

git添加本地仓库和远程仓库连接时,报没有相关的历史在分支上。

解决办法

git pull origin master --allow-unrelated-histories

使用–allow-unrelated-histories参数允许不相关的代码历史合并。这样就可以了。