Learning Goal
- Familiarize with the main tools of version control with git using RStudio’s graphical user interface.
- Practice creating a new project with RStudio GUI.
Learning Objectives
Following this lesson, students will be able to:
- Explain what is version control and why should we use it in research
- Use Rstudio to:
- create a new git repository locally
- understand the concepts of “staging” and “committing” file versions
- explain what is a hash
display, read and comprehend the git history
Day 1
- Discussion: What is version control and why should we use it.
- Lecture:
git
for version control- free
- open source
- distributed repository system (not centralized)
- faster to commit changes locally and offline
- staging area
- commit messages allow team communication
- Live coding Git basics in RStudio
- activating git for your project with RStudio: starting a local git repository
- checking the “git status” of your files
- adding files to the staging area: indicating our intention to version control files
- committing files
- it creates a unique numbered version of your work
- commit messages must be informative:
- viewing history: viewing the “git log” and “git diff” of versions that we have created
- ignoring files for version control using the
.gitignore
file- which files should we ignore?
- the “.Rproj” files
- directories are not version controlled if they are empty
- the difference between staging/adding a file or changes to a file and commiting them:
-
In-class exercise
- Create a new RStudio project on your computer called “bio”.
- Write a three-line biography for yourself in a file called me.txt, add and commit your changes.
- Modify one line, add a fourth line, add and commit the changes.
- Display the git history of your project. Describe the differences between the updated state and the original state of your repository. Do your commit messages are informative enough to describe the differences?
- Homework
Read: Best practices for commit messages
Day 2
Learning Goals
- Learn
git
tools for version control of remote repositories on GitHub- Practice usage of Unix shell commands to set up and do remote version control on GitHub
Learning Objectives
Following this lesson, students will be able to:
- Explain the difference between a local and a remote git repository
- Create a new repository on GitHub
- Set up git for usage with GitHub
push
andpull
changes to a remote repository- List alternative software to git for version control
- List other platforms for remote version control with git
- Explain why we use Git
Live coding
-
- Create a remote repository
- Connect local repository to newly created remote repository
- use SSH and not HTTPS, the latter is more secure
- Set up authentication to remote repositories
- Setting up keys and tokens
- create an SSH key pair
- give your key to GitHub
- manage your password
- Push local repository to remote with
git push
- The GitHub GUI
- create a README file
- look at the git history remotely on the Github GUI
- Pulling a remote repository to local repo with
git pull
- what happens locally when there are changes to remote?
- what about when there are no changes to remote?
- Look at the git history locally on the terminal with
git log
Group activity
- What is the difference between committing a change and pushing it?
- Read the comic, can you find three main differences between committing a change to a repository and pushing a change?
- Think of another example to illustrate the difference between
git commit
andgit push
. For example, I imagine that adding a song to my spotify queue is equivalent to committing a file, and then when the song is finally playing and made public that is like pushing the file to the remote repository 😜
Comic by Erika Heidi.
Optional activity
- What is the difference between fetching changes from a remote and pulling them?
.
Comic by Allison Hurst
Individual activity
- Create a remote repository called “bio” on your GitHub account.
- Add, commit and push your local repository to your newly created remote on GitHub.
- Add a line to your bio file using the GitHub GUI, and commit it.
- Modify another line of your bio on the GitHub GUI and commit it.
- Find the commit history on GitHub.
- Take a snapshot of the commit history displayed on GitHub and send it to your instructor.
- Now pull the changes into your local repository.
- Get your commit history on the terminal with
git log
, take a snapshot of it and send it to your instructor.