Skip to content
Neal W Morton edited this page Aug 27, 2018 · 6 revisions

Getting a copy of a project from GitHub

  • Get an account on GitHub
  • Send Neal your username so you can be added to the prestonlab group
  • To install using the GitHub app (does not work on TACC or on older Macs):
    • Install the app from the GitHub website
    • Sign into your account
    • Click on the + icon in the upper left; go to the clone tab
    • You should see the repository if you have access to it
    • Select the one you want and click the Clone button, then select where you want to place the repository
  • To install using ssh (does not require entering a password when installing code or making changes):
    • Set up an SSH key with GitHub (you only need to do this once for each computer, and then it will work for other code repositories). See the section "Adding an SSH key" below.
    • On GitHub, go to the page of the project you want. In the lower right, click on SSH so that the SSH clone URL is displayed. This is the URL you need to clone the repository.
    • On the computer where you want the code, type git clone [SSH clone URL], for example git clone [email protected]:prestonlab/fat.git to download the repository.
  • To install using HTTPS (requires entering a password when making any changes; doesn't seem to work on TACC):
    • On GitHub, go to the page of the project you want. In the lower right, click on HTTPS so that the HTTPS clone URL is displayed. This is the URL you need to clone the repository.
    • On the computer where you want the code, type git clone [HTTPS clone URL], for example git clone https://github.com/prestonlab/fat.git.
    • Enter your GitHub username and password to download the repository.

Adding an SSH key

Follow these steps to add an SSH key to GitHub so you can push and pull from git projects without having to enter your password.

  • On the computer where you want the code, check if there is a file in ~/.ssh/id_rsa.pub. If not, in the terminal run ssh-keygen. Hit enter through all the options to create a passwordless key.
  • Type cat ~/.ssh/id_rsa.pub; this will display the public key that you just created. Go to your account page on GitHub and click the settings icon in the upper right. Click on the "SSH keys" tab, then "Add SSH Key".
  • Copy the public key into the box; give the key a title so you will know what computer it corresponds to. You will need to generate and add a different key for each computer you use.

Managing Code

If you want to manage your own code for a project (e.g. study-specific code) through the lab's GitHub account, in a directory called "analysis" in the home directory:

  • Go on GitHub and create a new project under the prestonlab organization
  • Clone the project: cd ~/analysis; git clone [email protected]:prestonlab/[projectname].git
  • Add scripts to the directory
  • See the status of the project: cd ~/analysis/[projectname]; git status. You should see each of the script you added.
  • git diff will show detailed information about any changes made to each file. For it to display properly, you may need to run this command: export LESS=MIR. That sets the display program git uses, less, so it can do color coding correctly.
  • Add those scripts to the list of changes to commit: git add [script1] [script2] ...
  • Make the list of changes to the project: git commit -m 'add scripts for analyzing behavioral data'.
  • The -m flag is very important, since it describes the changes in each commit and can help a lot with keeping track of changes to code over time. It's required, so if you don't specify it, a text editor will open so you can write a message there.
  • Push the changes to GitHub: git push. This will backup your changes, and will make them accessible to other people with access to your project. You should now be able to see the latest version of your code on the GitHub website. Note that you can also edit files directly on the GitHub website.
  • To get the latest code from GitHub: git pull. This will pull in any changes and attempt to merge them with the versions of the files you have locally.