12/20/2023 0 Comments Merge branch with master git![]() ĭrwxr-xr-x 15 yusufshakeel staff 480 Oct 8 17:22. And finally we return back to the master branch and merge the dev branch changes into the master branch.Īfter the fast forward merge the pointer pointing at the last commit of the master branch is moved forward to point at the last commit of the dev branch.ĭrwxr-xr-x 5 yusufshakeel staff 160 Oct 8 17:21. Then we checkout the dev branch and commit some changes. Git performs a Fast forward merge if there is a linear path between current branch and target branch.Įxample: We have a master branch and we create a new dev branch from it. When we perform the merge operation a new file (sample.php) from the target (dev) branch is added to the current (master) branch. So, in the above merge example the target branch is the dev branch and the current branch is the master branch. But the target branch remains unaffected. So, new files get added, exisiting files, if modified, gets updated. When we merge the target branch into the current branch, the current branch gets updated to reflect the changes. ![]() Note! The merge was a Fast-Forward merge (more on that later in this tutorial). You can see that sample.php file got added to the master branch working directory after the merge from the dev branch. rw-r-r- 1 yusufshakeel staff 0 Oct 8 16:44 sample.php ĭrwxr-xr-x 15 yusufshakeel staff 480 Oct 8 16:44. rw-r-r- 1 yusufshakeel staff 0 Sep 18 21:10 index.phpĭrwxr-xr-x 3 yusufshakeel staff 96 Sep 12 19:46 jsġ file changed, 0 insertions(+), 0 deletions(-)ĭrwxr-xr-x 6 yusufshakeel staff 192 Oct 8 16:44. ĭrwxr-xr-x 15 yusufshakeel staff 480 Oct 8 16:43. ĭrwxrwxrwx 30 yusufshakeel staff 960 Oct 2 22:48. So, if we are on master branch (i.e., current branch) and we run the git merge dev command then we will merge the dev branch (i.e., target branch) into the master branch.ĭrwxr-xr-x 5 yusufshakeel staff 160 Oct 5 19:47. To merge a given branch into the currect branch we use the git merge command. So, we have already learned in the previous tutorials how to create branches and how to checkout branches. Pass it -no-ff argument to create history without fast forward.In this tutorial we will learn to merge branches in Git. If you do use -no-ff, the history is preserved much better: all feature commits are kept in a side branch and only the merge is in the main line.Ĭlick to download the batch file that demonstrates the problem (rename from. The end result is that you get very confusing commit history for the rest of the life of the project. The annoying part is that if it has already been pushed to origin, it is not easy to fix without force-pushes, and force-pushes are not always enabled. It does not look good: feature and master commits are now mixed in the main branch line. Since “feature” has all commits that “master” has plus some more, git by default will simply fast-forward “master” to be the same as “feature”, and the feature branch will effectively befcome the new master. Now the feature is ready to be merged back into master. Merge latest master into feature to resolve any conflicts.Add some commits to feature and to master.State after donig git merge -no-ff feature instead (good state): State after switching to master and doing git merge feature (bad state!): A few days ago I ran into a situation when I forgot to add -no-ff when merging a feature branch into master.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |