1

Simple question let's say i'm working on Feature A of my project and a friend is working on Feature B, we both started from the same master source code. And this happens:

  • I merge my branch onto master. (Feature A)
  • I push the project.
  • Then he merges his branch onto master. (Feature B)
  • He pushes the project.

Will my branch (Feature A) be lost in the process? How do you merge properly in this situation? (Should i merge my branch onto my friend's branch first and then he can merge onto master?) (He is probably gonna have to pull (from master) first before pushing but his code is not going to have Feature A anyway.)

Andrey Torres
  • 29
  • 1
  • 7
  • 1
    Unless they *force* push to master, they will have to combine your changes with their own before pushing to keep a consistent history. – jonrsharpe Aug 23 '17 at 21:17
  • 1
    Your friend simply has to pull from master (merge changes to master since he last branched) and push. And that is also why you should never force push. – Terry Aug 23 '17 at 21:36

1 Answers1

0

He won't be able to push directly to the remote repo because it history will have diverged from said remote.

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/[me]/[project].git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. 

I would recommend a git pull --rebase --preserve-merges on B side, in order for B to replay his/her commits, and then push back.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250