Version Control with Git

Install Git

for windows

  1. Download the Git for Windows installer from https://git-scm.com/download/win.
  2. Run the installer and follow the steps bellow:
    1. Click on “Next”.
    2. Click on “Next”.
    3. Keep “Use Git from the Windows Command Prompt” selected and click on “Next”. If you forgot to do this, rerun the installer and select the appropriate option.
    4. Click on “Next”.
    5. Keep “Checkout Windows-style, commit Unix-style line endings” selected and click on “Next”.
    6. Keep “Use Windows’ default console window” selected and click on “Next”.
    7. Click on “Install”.
    8. Click on “Finish”.
  3. If your “HOME” environment variable is not set (or you don’t know what this is):
    1. Open command prompt (Open Start Menu then type ‘cmd’ (without quotes) and press [Enter])
    2. Type the following line into the command prompt window exactly as shown: setx HOME "%USERPROFILE%"
    3. Press [Enter], you should see SUCCESS: Specified value was saved.
    4. Quit command prompt by typing exit then pressing [Enter]

For Mac

Install git-osx-installer.

For Linux

install `git’ from your distro’s package manager.

Lesson

Adapted from Version Control with Git by Software Carpentry.

git config --global user.name "Liming Wang"
git config --global user.email "lmwang+datascience@gmail.com"
git config --global color.ui "auto"

Exercise

  1. If you haven’t yet, commit your RStudio project to github;
  2. Add the GitHub account of your team partner as a collaborator to your repo;
  3. Exchange URL to your github repo with your team partner;
  4. Checkout your team partner’s repo in RStudio (File/New Project …, then Verision Control);
  5. Review his/her code and add comments for suggestions where the code can be improved;
  6. Commit your change (comments) with a proper commit message;
  7. Push your commit to GitHub;
  8. After your partner pushes his/her commit, switch back to your own repo & pull to get the updated files with your partner’s comments;
  9. Responded to the comments with your own comments or changes to your code, commit (with a commit message) and then push to GitHub;
  10. Repeat the above steps a few times.

Resources:

  1. Happy Git with R
  2. try Git
  3. Pro Git, a book by Scott Chacon and Ben Straub