Search code examples
gitgit-mergegit-branch

Safest way to merge my branch into master branch?


I have a branch called file_migration and I wanted to merge it with the master branch. I only want the files I have updated/added to be merged into master branch. If other people have made changes to master branch that are not captured in my branch, I don't want my merge to affect other peoples' changes.

For example, let's say the master's branch contains only 2 folders: folder_1 and folder_2. My file_migration branch contains changes I made to folder_1. I have NOT changed anything in folder_2, but someone else has made changes to folder_2. So folder_2 in my branch will be older than folder_2 in master. I want to make sure my merge to master branch only updates folder_1 and should not affect folder_2 in master branch (because folder_2 in my branch is older than folder_2 in master branch so I don't want my merge to affect folder_2).

What will be the best protocol to ensure I only apply my changes made to folder_1 to master branch without changing anything in folder_2? I've read this other question Safe way to merge my branch where people suggest they can simply git merge to master branch. But I am not sure if the situation mentioned in that question applies to my case.


Solution

  • Just merge it.

    Git is smart enough to know what was changed and what was not. It doesn't matter if your branch is out of date, if you did not change a file Git will not merge any change to the file. You can read more about merge strategies; Git uses several and will pick the most appropriate.

    Don't worry if the merge goes wrong, as with many things in Git you can undo it.