Git Collaborative Version Control

GitGitBeginner
Practice Now

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

Introduction

Git is a powerful version control system that allows developers to work collaboratively on a project. One of the key features of Git is the ability to merge branches. Merging allows developers to combine changes from one branch into another, making it easier to manage changes and keep track of different versions of a project.


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-12654{{"`Git Collaborative Version Control`"}} end

Merge a Branch and Create a Merge Commit

As a developer, you may need to merge a branch into the current branch, creating a merge commit. This can be a bit tricky if you're not familiar with Git. The problem is to merge a branch into the current branch, creating a merge commit, using the Git repository named https://github.com/labex-labs/git-playground directory.

Tasks

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

  1. Clone the repository, navigate to the directory and configure the identity.
  2. Create and switch to a branch called feature-branch.
  3. Add "This is a new line." to the README.md file, add it to the staging area and commit it, the commit message is "Add new line to README.md".
  4. Switch to the master branch.
  5. Merge the feature-branch into the master branch,which will create a merge commit with the message "Merge feature-branch".

This is the result of running git log:

commit 45b7e0fa8656d0aa751c7ca3cee29422e3d6cf05 (HEAD -> master)
Merge: d22f46b 1f19499
Author: xiaoshengyunan <@users.noreply.github.com>
Date:   Fri Jul 21 19:26:57 2023 +0800

    Merge feature-branch

commit 1f1949955387a154ff1bb5286d3d0a2b993f87e0 (feature-branch)
Author: xiaoshengyunan <@users.noreply.github.com>
Date:   Fri Jul 21 19:26:57 2023 +0800

    Add new line to README.md

Summary

Merging branches is an important part of working with Git. By following the steps outlined in this challenge, you should be able to merge a branch into the current branch, creating a merge commit. Remember to always test your changes before merging them into the main branch, and to communicate with your team to avoid conflicts and ensure a smooth development process.

Other Git Tutorials you may like