Version Control with Git

You should version control your scripts with Git.

I recommend the Using Git and GitHub with RStudio Cheatsheet for additional helpful commands.

Important

As long as you have your raw data backed up and your scripts version controlled, you can reproduce your results!

Verify Git Installation and Version

which git # request path to your Git executable
git --version # check your Git version

Introduce Yourself to Git

git config --global user.name "<username>"
git config --global user.email "<email>"

Setting Up SSH for GitHub on Terra

Reference for setting up SSH for GitHub on Terra:

https://github.com/DataBiosphere/terra-examples/blob/main/best_practices/source_control/terra_source_control_cheatsheet.md

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 "[email protected]"

# 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.pub

Step 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 ~/.bashrc

Git Clone

git clone [email protected]:<username>/<reponame>.git

Create 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 main

Add, Commit, and Push Files to Remote Repository

git add <file-name>
git commit -m "description"
git push