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.
You will need to install Git onto the command line using apt-get:
sudo apt-get install git
You need to configure git to use your account that you will have created on the github.com website.
git config --global user.name "Your Name" git config --global user.email "email@example.com"
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.
git config --global http.sslverify false
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.
git add folder/file
Once a file has been added you can commit it to the copy with the commit line.
git commit -m "reason for committing"
Finally you have to push those changes to the remote repository with push:
git push url branch-name(probably master)
If you want to remove a file from git then
git rm test.txt git commit -m "remove test.txt"