- vừa được xem lúc

Chapter 5: Collaborating with Git - Pull Requests and Merge Conflicts

0 0 11

Người đăng: Duc Nguyen

Theo Viblo Asia

This chapter belong to Getting Started with Git: A Beginner's Guide Series

Collaborating with Git is a crucial aspect of software development. When working on a project with multiple developers, it is important to have a version control system in place to track changes, merge code and resolve conflicts. In this chapter, we will discuss two important concepts in Git, pull requests and merge conflicts.

Pull Requests

A pull request is a way to notify others about changes you've pushed to a Git repository on GitHub. It allows other users to review your changes, discuss any modifications and merge them into the main branch. To create a pull request, follow these steps:

  1. Fork the repository you want to contribute to.
  2. Clone the repository to your local machine.
  3. Create a new branch to make your changes.
  4. Commit and push your changes to your fork.
  5. Open a pull request on the original repository.

Here's an example of the commands you would use to create a pull request in Git:

$ git clone https://github.com/[your-username]/[repo-name].git
$ git checkout -b [branch-name]
$ git add [file-name]
$ git commit -m "your commit message"
$ git push origin [branch-name]

Merge Conflicts A merge conflict occurs when two developers modify the same line of code in the same file. When Git tries to merge these changes, it does not know which change to keep and which to discard, causing a conflict. To resolve a merge conflict, you will need to manually edit the file to include both changes.

Here's an example of how to resolve a merge conflict in Git:

  1. Open the file with the conflict.
  2. Locate the conflict markers, usually indicated by <<<<<<<, =======, and >>>>>>>.
  3. Decide which change to keep and which to discard.
  4. Delete the conflict markers and other unnecessary lines.
  5. Save the file and close it.
  6. Commit the changes with a descriptive message.

In conclusion, pull requests and merge conflicts are important concepts in Git that every software developer should be familiar with. By understanding these concepts, you will be able to effectively collaborate with other developers, maintain version control and resolve conflicts when they arise.

Bình luận

Bài viết tương tự

- vừa được xem lúc

Đặt tên commit message sao cho "tình nghĩa anh em chắc chắn bền lâu"????

. Lời mở đầu. .

1 1 701

- vừa được xem lúc

Tập hợp những câu lệnh GIT hữu dụng

Dưới đây là một vài ví dụ về các câu lệnh Git mà tôi thường dùng. git config --global user.name "John Doe". git config --global user.

0 0 55

- vừa được xem lúc

Cấu hình CI/CD với Github (phần 2): Trigger một work flow

Events trigger. Bạn có thể cấu hình cho workflows chạy khi có một sự kiện nào đó xảy ra trên GitHub, theo một lịch có sẵn hoặc cũng có thể là một sự kiện nào đó xảy ra ngoài GitHub.

0 0 70

- vừa được xem lúc

Cấu hình CI/CD với Github (phần 1): Một ít lý thuyết

CI/CD là gì. Về mặt khái niệm là vậy nhưng về mặt triển khai thì CI/CD là quá trình tự động thực hiện các quá trình build, test, release, deploy khi có các trigger như commit/merge code lên một branch định sẵn hoặc có thể là tự động chạy theo một lịch cố định.

0 0 118

- vừa được xem lúc

Giới thiệu về Git LFS

. Git LFS là gì . Git LFS làm điều này bằng cách thay thế các tệp lớn trong repo của bạn bằng một con trỏ nhỏ.

0 0 29

- vừa được xem lúc

Git workflow được Google và Facebook sử dụng có gì hay ho

Với developer thì Git hẳn là công cụ rất quen thuộc và không thể thiếu rồi. Thế nhưng có mấy ai thực sự hiểu được Git.

0 0 66