Pushing to and Pulling from GitHub

GitHub 101 — Module 4/4

This is the fourth of four posts about GitHub for beginners.

We have been talking about Git a lot in the last two posts; maybe you forgot that this series is about GitHub but I did not! Now that we have a good knowledge on the version control system, let’s take a look on how to use GitHub to store our repositories.

Git is a distributed version control system, which means that the repositories are self-contained; data and meta-data are stored locally in the .git folder; you do not need a server or a central repository but this does not mean that you can not have these. If you are working in a project together with other people you probably want a copy of the repository stored in a place always available to them. That is where GitHub comes in.

Hands-On Time!

After having sign up for GitHub, create a new repository in it called LearningGit. After you have finished, GitHub will take you to your repository page, where you can easily find your remote address, which look like this:


With that we can upload the repository we are working on to GitHub. Run Git Bash if you are running Windows (which is found under the Start Menu), otherwise run Terminal, then enter…

cd ~/LearningGit

…to go to the locally-stored repository we have been working in. Now we are going to tell Git to link this repository with the repository we just created in GitHub. In order to do that, enter:

git remote add something https://github.com/USERNAME/LearningGit.git

something is the name we defined to that remote location. You can set any meaningful name you want.

Finally, send everything to GitHub:

git push something –all

Now refresh your page repository in the GitHub website and you should see your working directory there. One of GitHub’s nice features is this file explorer where you can not only view files but also edit them from your browser. Let’s take advantage of it to see how things work the other way around: pulling files from GitHub.

Click index.html from the file explorer then click in the little pencil at the right of the filename to edit it. Change the file in some way and commit the changes in the bottom of the page. Once you have done this, go back to Git Bash and issue the following command to update your local repository:

git pull something master

Now your local index.html file has the change you made using the GitHub web application.

Keep in mind that that change could have been pushed to GitHub by someone else that is collaborating with you and, when pulling from GitHub, you would receive it, what, in conjunction with branching, makes everything much easier (only remember to first enable collaboration in your repository).

Now you have the basics information about how to use Git and GitHub in order to:

  • Keep track of changes
  • Recover past versions
  • Experiment freely
  • Merge changes
  • Host your project remotely
  • Collaborate with others

This is more than enough to start, so go ahead, put this knowledge into action, and keep acquiring more knowledge; look for integrating Git in your preferred IDE, learn about the difference between pulling and fetching, research about stashing, and find out how to solve merging conflicts. Do not be intimidated! With what you already know you can play it by ear.