Pulling Changes from Remote Repositories into Git
So, in the previous lessons we learned how to send data to an remote repository. Let's now imagine a situation where the data in it has changed. This situation occurs when several people work on a project and each of them sends data to this common repository. Or there may be a situation when you work on different computers, for example, at home and at work. At work you send changes, and at home you want to receive them on your home computer.
Let's simulate such a situation. To do this, go to the project files on the GitHub website and edit any file, making changes to it. Let's get these changes to our local computer.
This is done using the fetch
command, followed by the name of the remote repository:
git fetch origin
This command will copy all the changes made in the remote repository since your last access to it. The changes will not appear in our files immediately, but will go to a special branch. The name of this branch will be built according to the following principle: the name of the remote repository, and then the branch name after a slash. In our case, it will be origin/master
.
In order for the changes to appear in our project files, we need to merge the changes into our branch. To do this, while in the master
branch, we will execute the merge command:
git merge origin/master
On GitHub, manually make changes to your project. Pull those changes into your local repository.