![]() |
VOOZH | about |
Git merge combines changes from different branches into one for smooth integration. If Git canβt merge changes automatically, a merge conflict occurs and must be resolved manually.
You are working on a dev branch where you create a file k.txt and commit it. When you check the logs, youβll see a commit showing that k.txt was added in the dev branch.
This can be broken into steps:
In the above example, merging is used to bring k.txt from the dev branch into the master branch.
git checkout master
git merge dev
Now k.txt appears in the master branch.
Note:master and main are default branch names in Git. Older versions use master while newer versions use main, but both serve the same purpose as the primary branch.
In the same scenario, if Git performs a fast-forward merge, it will only move the branch pointer without creating a new commit.
But if you want a separate commit to clearly show that dev was merged, you can use --no-ff.
git merge dev --no-ff -m "Merged dev into master"Now a new merge commit is added to the history.
Now imagine another situation in the same example:
When you try to merge, Git cannot decide which version to keep which creates a conflict.
Example Conflict:
Resolution: Edit k.txt with the desired content, then run:
git add k.txt
git commit -m "Resolved Conflict"
After resolving, the merge completes successfully.
If during this process you feel the merge is incorrect or too complex, you can cancel it.
git merge --abortThis brings your project back to the state before the merge started.