Skip to content

Latest commit

 

History

History
166 lines (129 loc) · 4.06 KB

git_lesson.md

File metadata and controls

166 lines (129 loc) · 4.06 KB

Git Lesson Plan

Before the workshop

Motivation

** Why should we be using version control?**

  1. To keep track of changes (avoid the mypaper_final_final_final_reallythistime.docx problem.)
  2. To give reasons for each change.
  3. To preserve multiple versions of documents simultaneously. (this can be done with "branches").
  4. To collaborate with others and not create conflicting versions of the same document.

Topics

  1. Introduction to Git
  2. Git in the command line
    • First steps
    • Setting up repositories
    • Tracking Changes
    • History
    • .gitignore
    • Using Github (and other remotes)
    • Collaborating
    • Conflicts
  3. Git in RStudio

Overview: What is git doing?

  • Git keeps track of your changes. It monitors changes as if they were separate from the document itself.

How do git commands work?

Git commands take the format git verb options

The first time you use git...

You will need to tell git who you are so it knows who made the changes in your documents.

git config --global user.name "Mickey Mouse"
git config --global user.email "mickey1234@gmail.com"

Optional: Change core editor to nano from vim (for more editor options see https://swcarpentry.github.io/git-novice/02-setup/index.html)

git config --global core.editor "nano -w"

Note: You can check out your settings with the following command

git config --list

Setting up a repository

repository: a storage area (usually a directory) where git can store all the history of a project and information of who changed what and when.

  1. Make a new repository
mkdir microbes
cd microbes
git init

Check the repository was created

git status
ls -a

You'll see a message about the branch, the commits, and a list of the files including the .git file.

Working in a repository

First we'll need some files...

nano cheese.txt

Type the following text in cheese.txt and then press ctrl+o ctrl+x to save changes and exit nano.

Cheese is made with milk.

The git workflow

  1. Make changes to file(s)
  2. "stage" (git add) those file(s).
  3. commit the changes (git commit -m "message about changes")

"the git workflow"

Now let's do this ourselves:

Check on git status

git status
git add cheese.txt
git commit cheese.txt -m "wrote about cheese ingredients"

Notes about commit messages:

  • like a lab notebook - should be informative
  • ideally, commit often and in small parts. This makes reverting back easier.
git status

Let's add some more changes...

nano cheese.txt

Type the following text in cheese.txt and then press ctrl+o ctrl+x to save changes and exit nano.

Cheese is made with milk and microbes.
Cheese is good.

Check on the status

git status

(cheese.txt has been modified, but not staged)

What if we forgot exactly what changed?

git diff
git diff --color-words # shows word-by-word changes

Shows line-by-line changes in our modified documents. Now that we know the changes, and like them, we can add and commit them.

git add cheese.txt
git commit cheese.txt -m "added microbes to ingredients list"

Now it's your turn:

  1. Create a new file called nutritional_yeast.txt
  2. Write the following line for nutritional_yeast.txt
Nutritional yeast is made with microbes.
  1. add and commit the file.

Looking back in time

Ignoring files

  • RSTUDIO

Using Github (and other "remotes")

Collaborating

Conflicts

Git in RStudio

Common points of confusion:

  • Github is not the same as git.
  • git can be used without a github account.
  • Github accounts allow other people to use the internet to connect with a git repository that is hosted there.