Contenido del Curso
GitHub Fundamentals
GitHub Fundamentals
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:
-
We simulated collaboration by making changes both locally and remotely to the
README.md
file; -
We first committed a change directly to the remote repository, then made a different change locally;
-
When we tried to push our local changes, we encountered a conflict because the remote repository had new updates;
-
To resolve this, we pulled the changes from the remote repository, which resulted in a merge conflict;
-
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.
¡Gracias por tus comentarios!