GitHub: Setting up a version control repository – Part 2

In the last GitHub tutorial, we created a repository for a project on GitHub then linked this to the project’s folder on our local computer. Linking the repository this way records the version history of our project on the Internet.

When we set up the GitHub repository, we used the command line to push the local repository to the GitHub repository, like so:

$ git remote add origin
$ git push -u origin master

What do these lines mean?

In Git, a remote repository is a version of your project that is hosted on the Internet or a network somewhere. A remote repository is useful because it allows you to collaborate with others by pushing data from a local repository to a remote repository, or by pulling data from a remote repository to a local repository. Any push to or pull from a remote repository sends along the whole version history of the project, so that information on contributions by collaborators and other project details are made transparent and can be distributed among many people.

When a local repository is first created, all data are assigned to a branch named master (by default). When a local repository is linked to a GitHub repository, we tell Git to add a remote repository named origin (by default) and link the local repository to it using the hyperlink. We then tell Git to push the local repository contents to origin from the master branch.

If a GitHub repository is public, or if you have access to a private repository, you want to access the contents of the repository by cloning (ie. downloading) the remote’s contents to the local computer:

$ git clone
Cloning into 'github_rocks'...
Username for '': 
Password for '': 
remote: Counting objects: 28, done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 28 (delta 2), reused 28 (delta 2), pack-reused 0
Unpacking objects: 100% (28/28), done.
Checking connectivity... done.

A clone can also be done from GitHub itself, using the green Clone or download button on the GitHub repository (Figure 1).

Figure 1:


Subsequently, any changes made on a local repository that are committed can be pushed back up to the remote repository (if you have write access):

git push origin master

and any commits pushed to the remote can be pulled down to the local repository:

git pull origin master


To set up a GitHub repository, link a local repository on your computer to a remote repository on a server somewhere in the cloud. You then push the local repository’s contents to the remote repository.

After this, any changes that are committed in the local repository can be pushed to the remote repository. Or, any changes (made by others) to the remote repository can be pulled down to the local repository. The version history of the project accompanies any push or pull.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s