I have been working on a development
branch for some time, meanwhile, another developer has been making changes to the master
branch (several commits to the master).
The master
branch now has content that I do not have in my development
branch.
Can I merge the development
branch without effecting the new commits in the master
branch? i.e. not overwrite any new work in the master
?
What is the best way to handle this?
No, the principle of merges in git is additive, you can't "overwrite" commits with a merge.
Initial situation
A---B---C---D <<< master
\
E---F <<< development <<< HEAD
Your coworker has made commits C
and D
. Let's now merge development
into master
.
git checkout master
git merge development
A---B---C---D---G <<< development, master <<< HEAD
\ /
E-------F
At this point, commits made on your development
branch are reachable from either branch, but the commits C
and D
are still here.
Assuming you guys are working on separate aspects of the project (and depending on your IDE) you can typically specify the files you want to commit/push. I'd suggest pulling from master
first and then copy over your changes and commit yours. Then create a pull request and merge the branches. It is always better to play it safe when working with git even if it takes a few more steps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With