Skip to content

Git Notes

Installation

OSX

Install git on OSX with:

brew install git

Linux

Install git on Linux with:

sudo apt-get install git

GitHub Desktop

Download and install GitHub Desktop.

Cloning a Repo

Clone a repo from Athenian Robotics with:

git clone https://github.com/athenian-robotics/ev3dev-python-intro.git

To find the URL for a particular repo, go to it's github page and click on the Clone or download button and copy the URL in the pop-up window. If your firewall blocks port 22, make sure that the repo URL begins with https:// and not git@. You can toggle between the two versions by clicking on Use HTTPS and Use SSH.

Setting up a Host Repo

If a Raspi does not have access to github.com (like on an FRC robot), then creating a host repo will make it much easier to update code on the Raspi.

Create a bare repo and a directory for holding code on the Raspi for myproject :

mkdir git
cd git
mkdir myproject.git
git init --bare myproject.git
mkdir myproject

Add a post-receive git hook that will trigger a git pull
into /home/pi/git/myproject whenever a git push is done to /home/pi/git/myproject.git. File changes in /home/pi/git/myproject will not be committable because that directory is not a cloned repo.

Edit /home/pi/git/myproject.git/hooks/post-receive and add:

#!/bin/sh
git --work-tree=/home/pi/git/myproject --git-dir=/home/pi/git/myproject.git checkout -f
echo "*** Updated myproject ***" >&2

Output from echo will be sent back the user as part of the git push CLI response.

  • Make the hook executable with:
    chmod +x /home/pi/git/myproject.git/hooks/post-receive
    

On the development machine, clone myproject from github and add the Raspi myproject.git directory as a remote repo with:

cd ~/git
git clone https://github.com/username/myproject.git
cd myproject
git remote add raspi pi@raspberrypi.local:/home/pi/git/myproject.git

You can now push updates from your development machine to the Raspi with:

git push raspi master

In the case of FRC, you would push to origin when your development machine is connected to a network reaching github.com and push to raspi when connected to your FRC robot network.