DEV Community

Cover image for 03 Git: Pull - Getting The Remote Changes
Jeet Mandaliya
Jeet Mandaliya

Posted on

03 Git: Pull - Getting The Remote Changes

This post falls in the series Git: An Essential Tool after 02 Git: 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. 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. In my case, it would be this. 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.

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.

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)
Enter fullscreen mode Exit fullscreen mode

The extension .md stands for MarkDown format. GitHub has great resources on basic markdown format here. 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.

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.

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.

Repository View After Adding README.md

Repository View After Adding `README.md`

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.

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 πŸ”₯ where we talk about what Git Branches are and what problems they solve while collaborating.


This post is originally written on my blog.

Top comments (0)