2 Jun 2013

How to use Git and Gibhub on Raspberry Pi


How to use Git and GitHub on Raspberry Pi

Git
Git is a free and open source distributed version control system. Let’s take that apart bit by bit.
Git is free and open source. You don’t need to pay to use it, and the source code is freely available. In practice that means that many pairs of eyes will be scanning the code and reading any bug reports, so defects in the code are likely to be found and fixed quickly.
But what does git do?
The fact that it’s a version control system means that it can help you keep track of files that are frequently changed. Most version control systems maintain a history of changes and make it easy for users to compare versions, to load previous versions, and to add new versions as appropriate. Most software developers use a version control system of some sort, and many use git.
Git has a range of features which make it attractive to developers, and one of those features is the fact that it supports distributed development. In other words, git is designed for use by teams in which the developers work in more than one location. 
You don’t need to know about we how we use git in our development process. The thing that matters is that you can use git, simply and easily, to get the latest version of our software on your Raspberry Pi.
Git expects developers to keep all the files for a project or library together in something called a repository. That’s just a grand name for a collection of files that belong together. All of our libraries are stored in git repositories, and those repositories are stored on GitHub.

GitHub

Hopefully that’s given you a feel for git and why we use it, but what about GitHub?
GitHub is a web-based service for people who want to use git. It’s widely used by teams who want to make some or all of their work publicly available under an open source license. Since that’s what we do, we feel that GitHub is a natural choice for us to store our code.
If you want to keep up-to-date with the code we’ve published on GitHub, you will need to install and use git.

Installing Git on your Pi

To install git, just pen a terminal window by typing Ctrls-Alt-T and invoke
sudo apt-get install git-core
You’ll be asked for your password and so long as your Pi has access to the internet and the debian RasPi repository is on-line you’ll see some activity which will show what’s going on as git is installed.
Once that stops you’ll be ready to go.

Using git to download our code

When you first install a local copy of a repository using git, you do so by creating what’s called a clone of the repository.
In order to install a local copy of the repository, click on the button marked ‘Git Read-Only’ and copy the text of the URI on its right. In our case, that’s git://github.com/quick2wire/quick2wire-python-api.git
It’s probably best to keep all your GitHub-based repositores in one place, so you may want to create a directory called git within your home directory. (In a command window, type cd ~
and then type mkdir git)
When you have done so, open a command window if necessary, change to your git directory by typing cd ~/git and create a copy of the GitHub content by typing
git clone git://github.com/quick2wire/quick2wire-python-api.git
Git will tell you that it’s created an empty repository and will then pull down all the current files from the repository on GitHub.
The README file on Git should tell you what do do to install the software in the repository.  in our case the recommended approach is to add the location of your new cloned repository to your Python Path.
Now you can use the software.
But how do you keep it up to date?

Keeping current

If you take  look at the GitHub page for a repository you can see when the files were last changed. If you open an account at GitHub (which has a free account option) you can chose to watch one or more repositories, in which case you will get notified whenever the repsoitory changes.
If a repository you’ve cloned has changed since you last updated it, it’s really easy to get back up-to-date. In a command window, change to the directory in which you cloned the repository. In our case, you’d typecd ~/git/quick2wire-python-api in a command window. Now just type git pull and git will update your repository so that it’s an exact copy of the current version on GitHub.
Depending on the way type of software in the repository, you may or may not need to repeat the installation procedure. If you’ve updated out gpio-admin repository, you’ll need to run through the installation process again, as described in the README for that repository in GitHub. In the case of the quick2wire-python-api package, you’ve already placed the code on your PythonPath so you should be ready to use the updated library without doing anything else.

Summary

You can use most code on GitHub by downloading, unpacking and installing an archive containing the code.
If the code is changing fast, and you want to stay up-to-date you may prefer to install git, use the clone command to create a local copy of the repository, and use the git pull command to refresh your copy when the version on GitHub has changed.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.