Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Syncing the Repositories | More Advanced Workflows
GitHub Fundamentals
course content

Зміст курсу

GitHub Fundamentals

GitHub Fundamentals

1. Introduction to GitHub
2. Basic Interaction with Remotes
3. More Advanced Workflows

book
Syncing the Repositories

As mentioned in the previous chapter, we need to sync our local branch with the remote repository. To do this, we should run the git pull command:

When we ran the git pull command, Git fetched updates but noticed our local and remote branches have diverged, meaning there are changes on both branches that need to be reconciled. Git couldn't proceed because it needs to know how to handle these differences, so let's set the merge option and run the git pull command again:

Git tried to automatically merge the local and remote changes to README.md, but ecnountered a merge conflict. Let's take a look at the commit tree, which indicates where the divergence and conflicts have occurred:

Resolving the Conflict

As you can see, our current local commit and the commit in the remote main branch share a common ancestor, but they diverge, leading to the merge conflict that we need to resolve. To do it, we'll open the README.md file in the Vim editor:

What we can do to resolve this conflict is enter insert mode by pressing i, remove the conflict markers, and combine these changes in the following way:

Next, you should press the Escape key, type :wq, and press the Enter key to save the changes and exit Vim. Now, to finish the merge, the README.md file must be added to the staging area and then committed using the respective commands:

Finally, we can safely run the git push command and verify that the three-way merge was successful by displaying the commit tree:

Let's break down what we did in these two chapters:

  1. We simulated collaboration by making changes both locally and remotely to the README.md file;

  2. We first committed a change directly to the remote repository, then made a different change locally;

  3. When we tried to push our local changes, we encountered a conflict because the remote repository had new updates;

  4. To resolve this, we pulled the changes from the remote repository, which resulted in a merge conflict;

  5. We then manually resolved the conflict in the README.md file using the Vim editor, committed the resolved changes, and successfully pushed the final updates to the remote repository.

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 2
We're sorry to hear that something went wrong. What happened?
some-alt