Git and GitHub
Branch Merging (Merging)
In this module, we will explore the process of branch merging in Git. Merging is a critical action to combine the work of different branches into a single branch, maintaining a clear and consistent project history.
What is branch merging?
Branch merging is the process of taking changes from one branch and combining them into another branch. This is essential when different developers work on multiple features or bug fixes simultaneously and it is necessary to consolidate all changes into the main branch of the project.
Types of Merge
Fast-forward merge
Occurs when the target branch has no additional commits since the source branch was created. In this case, the target branch simply advances to the latest commit of the source branch.
bash
Non-fast-forward merge
A new merge commit is created that unites the two commit histories when the target branch has additional commits after the source branch was created.
bash
Practical example of merging
Create and merge a branch
-
Create a new branch:
bash -
Make changes and commit on the new branch:
bash -
Switch to the main branch:
bash -
Merge the feature branch into the main branch:
bashIf it is a non-fast-forward merge:
bash -
Delete the merged branch if not needed:
bash
Conflict Resolution
Sometimes, changes in different branches can conflict. Git will attempt to automatically merge the changes, but if it can't, it will ask you to resolve the conflicts manually.
How to view conflicts
If there are conflicts, Git will indicate and modify the conflicting files to include markers that highlight the differences.
bash
- Introduction to Git and GitHub
- Installation and Configuration of Git
- Version Control Fundamentals
- Repository Creation and Cloning
- Making Commits and Tracking Changes
- Branch Management (branching)
- Branch Merging (Merging)
- Conflict Resolution
- Collaborative Work on GitHub
- Pull Requests and Code Reviews
- Advanced Git Usage (rebase, cherry-pick, etc.)
- Automation with Git hooks
- Continuous Integration with GitHub Actions
- Version Management and Release Deployment
- Conclusions and Best Practices in Git and GitHub