简体   繁体   中英

Github feature branch made branches automatically and merged it again

If you see the picture below, the blue branch is a feature branch Dev A and Dev B are working on. No one has branched off of the feature branch. But when Dev B removed some files, committed and pushed the changes to repo, it was created as a branch of the feature branch in git client graphical view (sourcetree). When Dev B checks git status , it still says the working branch is the same feature branch .

Dev A created some service class, committed and pushed it. It shows it still is in the feature branch . Why does this exactly happen, anyone can help explain please? Is it just graphical? Or either Dev A or Dev B didn't pull a change in between. Additionaly, on next git push by Dev B , the red new branch merged back to the feature branch.

Upon request, here is the git log of Dev B :

* af335d1 added...
*   63fa2a2 Merge branch 'feature-branch' of github.devops.abcCorp.local:namespace/project into feature-branch
|\  
| * c8d62c1 removed...
* | 74456c5 created...
|/  
* b321f9a fixed...
* 97d7c33 added...

git-feature-branch-conflict

What happened is Dev A tried to push, but it got rejected, so (s)he pulled and then pushed successfully.

A pull is equivalent to a fetch and a merge . For example, if you are on feature_branch :

git pull origin feature_branch

is equivalent to

git fetch
git merge origin/feature_branch

The reason there's a branch in the log is that, since Dev A 's local branch diverged from the remote branch, a fast-forward merge was not possible and git had to create a merge commit.

You can avoid this by using git pull --rebase to reapply your local commits on top of the remote branch.

              |  local feature_branch           remote reature_branch
--------------|------------------------------------------------------
before        | A--B--C                        A--B--D
              |
pull          | A--B--C--M
              |        \ /
              |         D
              |
pull --rebase | A--B--D--C'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM