Version Control with Git
“branch early, and branch often”
You should version control your scripts with Git.
Learning resources: https://swcarpentry.github.io/git-novice/01-basics.html
https://happygitwithr.com/
I recommend the Using Git and GitHub with RStudio Cheatsheet for additional helpful commands.
UK Biobank Audit tool
https://github.com/UK-Biobank/UKB-Git-Audit-Tool
scan to prevent sensitive data (PHI) from being committed to Git repositories.
GitHooks to check for specific items of data and ensure they are not committed
No data. No credentials. No tokens. No Jupyter notebooks that may inadvertently contain sensitive data in the output cells. Use .gitignore to exclude data folders.
As long as you have your raw data backed up and your scripts version controlled, you can reproduce your results!
GitHub SSH Setup (macOS)
Set up SSH authentication for GitHub so you can push/pull to both personal and lab repos without credential issues.
1. Set Your Git Identity
git config --global user.name "Your Name"
git config --global user.email "your-email@vumc.org"2. Generate a Key
ssh-keygen -t ed25519 -C "your-email@vumc.org" -f ~/.ssh/id_githubSet a passphrase when prompted (use 4+ random words like blue-microscope-river-42).
3. Add to macOS Keychain
ssh-add --apple-use-keychain ~/.ssh/id_github4. Configure SSH
Create ~/.ssh/config:
Host github.com
IdentityFile ~/.ssh/id_github
UseKeychain yes
AddKeysToAgent yes
5. Add Key to GitHub
pbcopy < ~/.ssh/id_github.pubGo to GitHub.com → Settings → SSH and GPG Keys → New SSH Key, paste, and save.
6. Test
ssh -T git@github.com
# Hi <username>! You've successfully authenticated...7. Clone and Remote URLs
Always use the SSH format with a colon (not a slash) after github.com:
# Cloning
git clone git@github.com:krantzlab/repo-name.git
# Switching an existing repo from HTTPS to SSH
git remote set-url origin git@github.com:krantzlab/repo-name.gitTroubleshooting
| Problem | Fix |
|---|---|
Permission denied (publickey) |
Run ssh-add -l to check if key is loaded. Re-add with ssh-add --apple-use-keychain ~/.ssh/id_github |
does not appear to be a git repository |
Check your remote URL — make sure it uses : not / after github.com |
| Passphrase prompt every time | Verify UseKeychain yes is in ~/.ssh/config |
Setting Up SSH for GitHub on Terra
Reference for setting up SSH for GitHub on Terra:
You need to do this one time for each new workspace you create on Terra (You need to run source ~/.bashrc every time you resume your workspace to start ssh and the path for your public key)
These code blocks are meant to be copied and pasted to run in the command line.
Step 1
git config --global user.name "<username>"
git config --global user.email "<email>"Step 2
# set your github user.name
git config --global user.name "<username>"
# set your github user.email
git config --global user.email "<email>"# start the ssh agent
ssh-agent -s
# make a directory to later save your ssh key (public and private key)
mkdir -p ~/.ssh
# create your ssh key pair
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -C "me@institution.org"
# you don't have to specify a key password, just leave empty and press enter
# print your ssh public key to your terminal to copy and paste when adding a new new SSH key at https://github.com/settings/keys
cat ~/.ssh/id_ed25519.pubStep 4
Add your public key to your github SSH keys. This has to be done on github, https://github.com/settings/keys
Step 5
# add start ssh-agent to your .bashrc profile
echo 'eval "$(ssh-agent -s)"' >> ~/.bashrc
# add the path to your SSH key
echo 'SSH_KEY=~/.ssh/id_ed25519' >> ~/.bashrc
# add your ssh key using it path
echo 'ssh-add "$SSH_KEY"' >> ~/.bashrc
# run your updated .bashrc profile
source ~/.bashrcGit Clone
git clone git@github.com:<username>/<reponame>.gitCreate a New Repository on GitHub
Go to GitHub to create your new repository, then initialize your repository from the command line.
cd </path/to/your-r-project-folder>
echo "# your-r-project-folder" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/<user.name>/<your-repository>.git
git push -u origin mainAdd, Commit, and Push Files to Remote Repository
git add <file-name>
git commit -m "description"
git push