git:出现Your branch and ‘origin/zq-dev’ have diverged,and have 1 and 1 different commits each, respectively.
(use “git pull” to merge the remote branch into yours)(说origin/zq-dev出现分叉)怎么办?
1.为防止zq-dev分支内容的丢失,先合并zq-dev到master:git merge zq-dev
2.使用git status查看此时提交情况
On branch master,Your branch is ahead of ‘origin/zq-dev’ by 4 commits.(use “git push” to publish your local commits)
3.使用 git log –graph –pretty=oneline –abbrev-commit命令
* ae49907 (HEAD -> master) `Merge branch ‘zq-dev’
|\
| * 9560204 (origin/zq-dev, zq-dev) modify file
* | 3efb899 2
* | 21af99d 1
* | a2a0994 add content 1
|/
* 80b980f add 9
* 2c3b24f ‘添加文件’
发现本地master分支对应的远程分支为origin/zq-dev,这就对了,(这是我先前使用此命令git push -u origin master :zq-dev 造成的)
4.然后尝试git push
git push
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:zq-dev
To push to the branch of the same name on the remote, use
git push origin HEAD
To choose either option permanently, see push.default in ‘git help config’.
出现:说当前分支的关联分支不匹您当前分支的名称。?(原来我使用过这个命令在zq-dev分支上:git push –set –upstream origin zq-dev,也就是说
本地zq-dev分支与远程分支zq-dev相关联了,但是远程分支zq-dev是从本地master分支push上去的,只是名称不同而已)
5.删除本地zq-dev分支与远程分支zq-dev
git branch -D zq-dev
Deleted branch zq-dev (was 9560204).
git push origin -d zq-dev
[deleted] zq-dev
6.查看此时所有分支
git branch -a
* master
remotes/origin/master
7.再次然后尝试: git push
fatal: The upstream branch of your current branch does not match
the name of your current branch. To push to the upstream branch
on the remote, use
git push origin HEAD:zq-dev
To push to the branch of the same name on the remote, use
git push origin HEAD
To choose either option permanently, see push.default in ‘git help config’.
8.根据提示使用命令:git push origin HEAD
To github.com:ZSGH123/git_test.git
! [rejected] HEAD -> master (non-fast-forward)
error: failed to push some refs to ‘git@github.com:ZSGH/git_test.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.
9.根据提示使用命令:git pull
Your configuration specifies to merge with the ref ‘refs/heads/zq-dev’
from the remote, but no such ref was fetched(还是有错误)
10. git status
On branch masterYour branch is based on ‘origin/zq-dev’, but the upstream is gone.(use “git branch –unset-upstream” to fixup)
11.根据提示使用命令:git branch –unset-upstream
12. 在git status查看:没有问题了
On branch master
nothing to commit, working tree clean
13.重新push master分支到远程
git push
fatal: The current branch master has no upstream branch.To push the current branch and set the remote as upstream, use
git push –set-upstream origin master
14.根据提示使用命令:git push –set-upstream origin master
To github.com:ZSGH123/git_test.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘git@github.com:ZSGH123/git_test.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.
(还是出现错误)
15.根据提示使用命令:git pull
git 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:
git branch –set-upstream-to=origin/<branch> master
16.根据提示使用命令:git branch –set-upstream-to=origin/master master
Branch ‘master’ set up to track remote branch ‘master’ from ‘origin’.(提示已经关联)
17 git status查看
On branch master
Your branch and ‘origin/master’ have diverged,
and have 7 and 1 different commits each, respectively.
(use “git pull” to merge the remote branch into yours)
(说origin/master出现分叉)
18.使用命令 git rebase origin/master 解决
19.git status查看
On branch master
Your branch is ahead of ‘origin/master’ by 7 commits.(use “git push” to publish your local commits)
20.根据提示使用命令: git push
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 4 threads
Compressing objects: 100% (21/21), done.
Writing objects: 100% (21/21), 4.39 KiB | 749.00 KiB/s, done.
Total 21 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), done.
To github.com:ZSGH123/git_test.git
fe9e915..ede8e31 master -> master(成功)