I have two developers working simultaneously, one on master (dev1) and one on another branch (dev2). The master is being treated as the “mainline”. Dev1 regularly merges the changes from the branch of dev2 as follows:
git checkout master
git merge origin/branch1
git push origin master
This merges the branch with the master for a deployment, but dev2 also wants to get the latest changes from the master after the merge is complete. I am thinking this is the best approach:
git checkout branch1
git rebase master
Is this correct?
In Github, I noticed that the branch they were working on no longer appears and no one deleted it. I’m pretty sure rebase or merge will not delete the branch unless you tell it to. Let me know otherwise.
Basically, the graph would look something like:
b1 b2 b3 b4...
/ \ / \
m1 m2 m3 m4 m5...
m3 and m5 are where dev1 will merge b2 and b4, respectively.
The rebase is only valid if
dev2is rebasing unpublished commits.But
dev2rebased commits already pushed to origin (and potentially already merged bydev1intomaster), then it is not the right approach, because the SHA1 are changed, and the next merge ofbranch1bydev1won’t just merge new commits, but all commits, even those already merged.In this specific situation,
dev2needs to mergemasterwithgit merge master– that will avoid those problems.