Merge a Branch

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

Git is a popular version control system that allows developers to collaborate on projects efficiently. One of the key features of Git is the ability to merge branches. Merging a branch allows you to combine changes from one branch into another, making it easier to manage changes and collaborate with others.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/BranchManagementGroup(["`Branch Management`"]) git/BranchManagementGroup -.-> git/merge("`Merge Histories`") subgraph Lab Skills git/merge -.-> lab-12655{{"`Merge a Branch`"}} end

Merge a Branch

Your task is to merge a branch into the current branch using Git. You will need to switch to the target branch and then merge the source branch into it. This can be useful when you want to combine changes from a feature-branch-A branch into the master branch of your project.

Tasks

For this challenge, let's use the repository from https://github.com/labex-labs/git-playground.

  1. Navigate to the directory and configure the identity.
  2. Create a feature-branch-A branch. Switch to it.
  3. Add "hello,world" to the file2.txt file, add it to the staging area and commit it with the message "fix file2.txt".
  4. Switch to the master branch.
  5. Merge the feature-branch-A into the master branch.
  6. Resolve any conflicts that may arise during the merge process.

This is the result of running git log:

commit e2b80358ae6e4c3b8439cf111a4672a188739290 (HEAD -> master, feature-branch-A)
Author: xiaoshengyunan <xiaoshengyunan@users.noreply.github.com>
Date:   Fri Jul 21 18:51:00 2023 +0800

    fix file2.txt

Summary

Merging a branch in Git allows you to combine changes from one branch into another. This can be useful when you want to combine changes from a feature-branch-A branch into the master branch of your project. To merge a branch, you need to switch to the target branch and then use the git merge command to merge the source branch into it.

Other Git Tutorials you may like