03 Git: Pull - Getting The Remote Changes
Tags: github, git
Published: 2021-01-28 00:43:16

This post falls in the series [Git: An Essential Tool](https://webdevjeet.me/tag/git-an-essential-tool-for-devs/) after [02 Git: Git Remotes and GitHub](https://webdevjeet.me/2020-12-git-remotes-and-github/). In that, we discuss what git remotes are and how we can use them to have a remote copy of our Git repo in the code hosting platform for version control and collaboration like [GitHub](https://github.com). I would genuinely recommend reading it before reading the current post.

### Git Pull: Getting Changes From A Remote Server (ex. GitHub)

Many times we require to work collaboratively on a project and make changes to software concurrently. When we're editing files on our machines locally and then pushing it on GitHub, other collaborators might also want to push their code to GitHub to collaborate.

Git Pull helps us to get the changes done by other collaborators(or by us using GitHub Website). This process can be best explained with help of an example and that's exactly what we're going to do. So let's dig in and go to the repository that we created in [02 Git: Git Remotes and GitHub](https://webdevjeet.me/2020-12-git-remotes-and-github/). In my case, it would be [this](https://github.com/sereneinserenade/first-repo). Here is what we are going to do.

*   Add a new file named `README.md`
*   Add dummy content to it.
*   Git Pull to get `README.md` that we created.

### GitHub: Adding A New File To Repo

On visiting repo on GitHub, we see the view of repo which has an `Add File` dropdown button in the middle of the top-right controls section.

<figure>![](https://dev-to-uploads.s3.amazonaws.com/i/m6lzh35yln58il904n4q.jpg)</figure>

Two options `Create new file` and `Upload files` are visible in the dropdown. For the sake of simplicity, we're gonna go for `Create new file`. On hitting that button, we're gonna be redirected to a page that looks like the following.

<figure>![](https://dev-to-uploads.s3.amazonaws.com/i/v73oemwas63vrr8idfqz.jpg)</figure>

As mentioned in the list of things to do, we're going to name the file `README.md`. There is a noble reason for it that is fused with the default repository view of GitHub, which we'll see at the end. Following is the text, that is written in the content section.

```
# first-repo
> This repo is for the [series Git: An Essential Tool](https://webdevjeet.me/tag/git-an-essential-tool-for-devs/)  on [My Blog](https://webdevjeet.me)
```

The extension `.md` stands for `MarkDown` format. GitHub has great resources on basic markdown format [here](https://docs.github.com/en/free-pro-team@latest/github/writing-on-github/basic-writing-and-formatting-syntax). If we like, we can also see the preview of our markdown that we wrote in the `Edit new file` section rendered directly inside the `Preview` tab. Here's what it looks like.

<figuree>![](https://dev-to-uploads.s3.amazonaws.com/i/j8gkz0gnatyjshfz0rdu.jpg)</figure>

After adding content in `README.md` as per our willingness, we can continue with committing the file. Add any commit message you like, here I've written `++ README.md` which is my way of writing commit messages, with which I immediately recognize that we added a new file named `README.md` in this commit. Since we'd discuss branches later in its specific post, that focuses on branches, we're gonna leave the first radio `Commit directly to the master branch` Selected.

<figure >![](https://dev-to-uploads.s3.amazonaws.com/i/1ftrjz77uwfbc0rntnp0.jpg)</figure>

As soon as we click on `Commit new file` we'll be redirected to the home page of the repo, but this time, GitHub has a slight new surprise ready for us as mentioned before.

<figure>![Repository View After Adding README.md](https://dev-to-uploads.s3.amazonaws.com/i/9xk0g40b7k26dqrx4n5m.jpg)

<figcaption>Repository View After Adding `README.md`</figcaption>

</figure>

That's right, GitHub shows the content of `README.md` in the root directory of the repo rendered on the repo page by default. `README.md` is in the general run of things used to show information about the repo and that's the exact thing we did here too!

### Command: Git Pull

Now that we've added the file on GitHub, we can go to our code and run `git pull` to update the state of the repository to be in sync with the state of the repo on GitHub.

<figure>![](https://dev-to-uploads.s3.amazonaws.com/i/n0o7pm58us8d0zuw85on.jpg)</figure>

Running `git pull` will always show which files have been added or modified alongside with total numbers of lines added/modified in a particular file. In our case, we can see something like `README.md | 3 +++` which means `README.md` file had changes in 3 lines and `+++` means all of them were additions and not modifications. No modifications also make perfect sense because we added this file for the first time to our project.

Git pull updates local repo with the new information of remote repo and that allows us to not only fetch changes done in GitHub website by us but also changes done by other collaborators in GitHub. And in most cases, you will find yourself getting changes from collaborators because we rarely edit/create/upload files from GitHub as we can do it far better with help of commands like `git push`.

**Whoopee ✅ , now you know how to update your local repo with the latest changes with** `**git pull**` **!!!🔥**

Next post in the series is [04 Git: Branches Are Breathtaking 🔥](https://webdevjeet.me/2021-01-04-git-branches-are-breathtaking/) where we talk about what Git Branches are and what problems they solve while collaborating.

---

This post is originally written [on my blog](https://webdevjeet.me/2021-01-git-pull-getting-the-remote-changes/).