Git for Raspbery Pi Users

One of the challenges for a Raspberry Pi developer/experimenter is keeping your files safe and backed up easily. You could of course use a USB stick but then you need to swap this between device and its not easy to share your code with others. If you are working on a collaborative project or sharing code across multiple devices then there are easier ways to do this. Google Drive does not play well with code files and although I’m a big fan of Dropbox there is an alternative – GITHUB.

The purpose of this blog post is to show you how to do the basics in Git on a Raspberry Pi.

Installing

You will need to install Git onto the command line using apt-get:

Setting Up

You need to configure git to use your account that you will have created on the github.com website.

If you are behind a firewall (e.g. a school one) and are getting errors that look like server certificate verification failed then you will probably find that the following line from Stack Exchange 21181231 solves this. Its not an ideal solution but for the purposes of educational non-sensitive experiments its probably the easiest.

Creating a repository

  • Go to the github website, click on Repositories and click New to create one.
  • Go to the Repository page and make a note of the url found under Clone or Download
  • In a command window on your Pi type git clone url to create a local copy of your repository.
  • You now have a local copy of your repository that you can work with.
  • git status will tell you the status of the copy.

Merging Changes and Adding Files

If you have made changes or added files then you will want to sync them back to the remote copy.  Remember, it is sometimes useful to see the status of your copy with the git status command.

Once a file has been added you can commit it to the copy with the commit line.

Finally you have to push those changes to the remote repository with push:

Removing Files

If you want to remove a file from git then

About CDB 361 Articles
Self-Employed Software Developer, Spark, Property Management, Hobby Forestry, Ex-Teacher, Engineering - Wood, Metal, Electrics & Computers. Outdoors - Walk, Cycle, Kitesurf,

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.