Skip to content

Latest commit

 

History

History
312 lines (213 loc) · 6.34 KB

content.md

File metadata and controls

312 lines (213 loc) · 6.34 KB

name: inverse layout: true class: center, middle, inverse


Git(Hub) Workshop

Ando Emerencia and Frank Blaauw

University of Groningen,
Developmental Psychology / Computer Science


layout: false

Outline

  • Why do I need git?
  • Introduction to git and GitHub
  • How do we use git?
  • Hands-on workshop

Why do I need git?

  • Code History

    • no more script_final.R, script_finalDEF.R, script_finalDEFV2.R
  • Reverting changes

    • rolling back to an earlier, working version
  • Collaborating with colleagues

    • sharing code without difficult merges and usb-sticks
  • Code review

    • check each other's code to guarantee code quality

For what is git useful?

  • Version Control System
  • Managing plain text files (R syntax, Matlab files, source code, txt files)

For what is git not useful?

  • Managing microsoft office documents
  • Storing data

???

  • Git is a version management system, which means that it can keep track of earlier versions of your source code / documents.
  • With plain text files we mean anything that is readable from notepad (generally source code or simple files). Not binaries.

The git basics

.pull-left[

Discussed now

  • Repositories
  • Clone
  • Pull
  • Add
  • Commit
  • Push
  • Branches and pull-requests ]

--

.pull-right[

Not discussed now

  • Checkouts
  • Rebasing
  • Cherry-picking
  • Tags
  • Forks ]

??? Each of these will be covered in more detail. The items on the right are added for reference only.


Repositories

.center[ Git flow ]

  • (Cloud hosted) remote location containing your code
  • GitHub is a provider of hosted git repositories
  • Repository can be either private (just for you) or public (for everyone)

???


Clone

.center[ Git flow ]

  • Downloading a remote repository to your local machine
  • Only needed once per repository, per machine you need to access your code on

Pull

.center[ Git flow ]

  • Updating your local working copy with the latest version from the git provider
  • Do this every time you want to pull in changes from the remote repository

Add / stage

.center[ Git flow ]

  • Selecting files / changes that you would like to store in git
  • You will have to do this every time you want to store changes or files

??? Git follows multiple steps in order to sync your code to a remote repository. It starts with actually selecting which files you'd like to synchronize.


Commit

.center[ Git flow ]

  • With a commit you can combine all the staged files into a single update
  • A commit comes with a commit message. In these messages you can write what you changed and why you changed something

??? With a git commit you actually combine your changes into a single sort of package, to which you provide a useful name.


Push

.center[ Git flow ]

  • With a push you upload your commits to the git provider (in our case GitHub)
  • You have to push in order to share your commits with everyone.

??? Finally you push your local commits to a remote repository, to store them or to share them with the world.


Branching - the master

.center[ Master ]

Supposed to be the stable version of the code.


Branching - a feature branch

.center[ Branch ]


Branching - Pull request

.center.small[ Branch ]

Moment to review code before merging it to master.


Branching - merged

.center[ Branch ]

A pull request causes the change to be merged into master.


A basic collaboration workflow

  • Clone a repository.
  • Create a new branch.
  • Make changes in that branch and add / commit / push to GitHub.
  • Create a pull request and ask others to review the changes.
  • If changes are ok, merge the branch into master.

Other, more advanced topics (not discussed today)

  • Git has a powerful command line interface
  • You can use public / private key SSH keys instead of using a username and password
  • GitHub can be combined with various services for automatically performing running tests on the code in GitHub (e.g., CircleCI)

name: inverse layout: true class: center, middle, inverse

Hands on


layout: false

Signing in to MyUWP

  • Open https://uwp.rug.nl and login
  • Click on Workspace desktop
  • When you are logged in, start the Google Chrome browser
  • All the next steps should be performed from within the UWP client.

Creating a GitHub repository

  • Log in on https://github.com
  • Click on the green New button next to Repositories
    • Fill in a name for the repository
    • Description is not necessary
    • Make it a public repository
    • No need to initialize it with anything
    • Click on Create repository
  • Click on the clipboard button to copy the repository url.

Install git


Configuring R Studio to work with git

  • Open the Windows start menu, type: R studio
  • In R Studio, Open the Tools menu and select Global options
    • Go to Git/SVN
    • Browse to the correct git executable (e.g. C:/Users/pnumber/AppData/Local/Programs/Git/bin/git.exe)
    • Click OK
  • Close R Studio

Cloning a repository in R Studio

  • Open R Studio again
  • Go to File and select New project
    • Select Version control
    • Click on Git
    • Paste the repository URL
    • (optional) change the directory to store the code in
  • Click on Create Project

Creating a new R file

  • Go to File, New File, R Script
  • Add some simple R code, e.g.,
print(2 + 2)
  • Save and choose a filename ending in .R

Adding the new file to git

  • Click on the tab named git (right side)
  • Click the Diff button to see an overview of the changes
  • Check all changed files to add them to the staging area (could take some time)
  • Add a descriptive commit message and click commit
  • Press close when the commit is done
  • Now press push to upload the changes to GitHub
  • Fill out your username and password

???

  • Altijd eerst een diff doen!
  • Username and password worden bewaard ie voor de session, dus dat is wel hip

name: inverse layout: true class: center, middle, inverse

Questions?