Resul Umit
post-doctoral researcher at the University of Oslo
interested in representation, elections, and parliaments
Resul Umit
post-doctoral researcher at the University of Oslo
interested in representation, elections, and parliaments
teaching workshops also on
Resul Umit
post-doctoral researcher at the University of Oslo
interested in representation, elections, and parliaments
teaching workshops also on
Half a day, on how to
Half a day, on how to
Using Git and GitHub, through
Half a day, on how to
Using Git and GitHub, through
Most useful for those working with pain text
Research projects have many versions, as they are typically completed
Research projects have many versions, as they are typically completed
With many versions created over time, in different sittings ..., there emerges various challenges
The Git-and-GitHub workflow has two steps
The Git-and-GitHub workflow has two steps
Git creates, saves, and tracks versions
Github keeps a copy online
The Git-and-GitHub workflow might seem daunting to adopt at first
The Git-and-GitHub workflow might seem daunting to adopt at first
Existing workflows might seem easier to keep
The Git-and-GitHub workflow might seem daunting to adopt at first
Existing workflows might seem easier to keep
Give the Git-and-GitHub workflow a chance
Part 6. Third-Party Applications
Sit in groups of two
Sit in groups of two
Type, rather than copy and paste, the code that you will find on these slides
Sit in groups of two
Type, rather than copy and paste, the code that you will find on these slides
When you have a question
Slides with this background colour indicate that your action is required, for
setting the workshop up
completing the exercises
* These slides are and will remain available at https://resulumit.com/teaching/git_workshop.html.
01:00
To make you aware what is possible with Git and GitHub
Google, and perseverance are all we needTo make you aware what is possible with Git and GitHub
Google, and perseverance are all we needTo encourage you to convert into the Git and GitHub workflow
Materials mimic a simple academic project
imagined to introduce a new dataset
in the structure shown on the right
git_workshop-materials | |- data | | | |- journals.csv | |- manuscript | | | |- journals.docx | |- journals.pdf | |- journals.Rmd | |- README.md
Download the materials from https://github.com/resulumit/git_workshop/tree/materials
Code -> Download ZIP
Unzip and rename the folder
unzip to a location that is not synced
rename the folder as YOURNAME_git_workshop
resul_git_workshopdata\journals.csv
a dataset created with the fabricatr package (Blair et al., 2019), imagined to explore the Google Scholar rankings of fictitious journals
includes the following variables
manuscript\journals.docx
manuscript\journals.docx
There are two other versions of paper.docx in the same folder
saved in PDF and R Markdwon formats respectively
manuscript\journals.pdfmanuscript\journals.RmdREADME.md
Git is a software that
Git is a software that
To get this software
GitHub is a hosting service, or a website, that
GitHub is a hosting service, or a website, that
To sign up for this service
Repositories -> New -> Repository name (e.g., "git_workshop") -> Public -> Create repository
observe that
repository URLs have the following structure: https://github.com/USER_NAME/REPOSITORY_NAME
Terminal, the address gets the .git extension
There are two types of repositories
public repositories
There are two types of repositories
public repositories
private repositories
GitHub Desktop is a software that
GitHub Desktop is a software that
To get this software
Git Reference Manual
Pro Git (Chacon and Straub, 2021)
Git Cheat Sheet
Git Visual Cheat Sheet
Type, and enter, your commands into the shell
ctrl + v will not paste into shell
Git commands
git$ git
Git commands
git$ git push
Git commands
git$ git --version
Git commands
git$ git push origin master
Git commands
git$ git commit -m "I revised the abstract"
config command to introduce yourself to Gitgit config --global user.name "YOUR-NAME" git config --global user.email "YOUR-EMAIL-ADDRESS"
git config --global --listcdUse the cd command to
$ cd
/m
cdUse the cd command to
$ cd ../pc/Desktop/resul_git_workshop
../pc/Desktop/resul_git_workshop
cdUse the cd command to
$ cd ../pc/Desktop/resul_git_workshop
../pc/Desktop/resul_git_workshop
Note that
cd is not a git commandgitlsUse the ls command to list the contents of
$ ls
data/ manuscript/ README.md
lsUse the ls command to list the contents of
$ ls data/
journals.csv
1) Move into the directory holding the workshop materials
cd command
2) See the contents of the folder in the shell
ls command02:00
git initUse the git init command to turn a directory into a git repository directory
$ git init
Initialized empty Git repository in ../resul_git_workshop/.git/
git init — NotesThe git init command creates a hidden .git subdirectory, with the structure on the right
currently mostly empty
not visible with ls
ls -al
File Explorer -> View -> Hidden items
hidden, so that it is harder to delete or alter by mistake
.git ├── refs │ ├── tags │ └── heads ├── objects │ ├── pack │ └── info ├── info │ └── exclude ├── hooks │ (12 files) ├── HEAD ├── config └── description
git addUse the git add command to start tracking
$ git add README.md
.git
│
...
├── objects
│ ├── pack
│ ├── info
│ └── 8f
│ └── ec6eb5b06dc535825227bd0e6883882075639b
│
├── index
...
git addUse the git add command to start tracking
$ git add README.md data/journals.csv
git addUse the git add command to start tracking
$ git add .
git add — Notesgit add command alone does not create a versiongit commit command, without which git add — Notesgit add command alone does not create a versiongit commit command, without which git add command (and then, the git commit command)git add — Notesgit add command alone does not create a versiongit commit command, without which git add command (and then, the git commit command)$ git rm --cached README.md
$ git rm --staged README.mdgit commitUse the git commit command to take a snaphot of, or to version, a repository
$ git commit -m "adding the README file"git commitUse the git commit command to take a snaphot of, or to version, a repository
$ git commit -m "adding the README file"
.git
│
...
├── objects
│ ├── pack
│ ├── info
│ ├── 8f
│ │ └── ec6eb5b06dc535825227bd0e6883882075639b
│ │
│ ├── b2
│ │ └── 1ac00c3e97d186c3797908a79846dcde0b305a
│ │
│ └── fd
│ └── cb0ad247419c81076c8aec4021091f3ed630b0
...
git commitUse the git commit command to take a snaphot of, or to version, a repository
$ git commit -m "adding the README file"
Note that
git commitUse the git commit command to take a snaphot of, or to version, a repository
$ git commit -m "adding the README file"
Note that
git commitUse the git commit command to take a snaphot of, or to version, a repository
$ git commit -m "adding the README file"
Note that
Recall that
git add command3) Start tracking the README.md file
git add command
4) Take a snapshot of the current version of the file
git commit command03:00
git statusUse the git status command to check the status of your repository
$ git status
On branch master
Untracked files:
(use "git add
data/
manuscript/
no changes added to commit (use "git add" and/or "git commit -a")
5) Check the status of your repository
git status command6) Make a change to the README.md file, and save
7) Check the status of your repository again
8) Commit the new version
07:30
git logUse the git log command to see the changes in reverse order
$ git loggit logUse the git log command to see the changes in reverse order
$ git log
commit 241b7285a00d47d69655d4a4afcd50989d5b50a8 (HEAD -> master)
Author: Resul Umit <resulumit@gmail.com>
Date: Sat Mar 6 09:27:32 2021 +0100
correct the maths error
commit fdcb0ad247419c81076c8aec4021091f3ed630b0
Author: Resul Umit <resulumit@gmail.com>
Date: Sat Mar 6 08:55:21 2021 +0100
adding the README file
git logUse the git log command to see the changes in reverse order
oneline flag returns a summary$ git log --oneline
241b728 (HEAD -> master) correct the maths error
fdcb0ad adding the README file
git logUse the git log command to see the changes in reverse order
oneline flag returns a summary$ git log --oneline
241b728 (HEAD -> master) correct the maths error
fdcb0ad adding the README file
Note that
HEAD refers to the snapshot of your last commitmaster is the default branch namegit branchUse the git branch command to create a copy of your repository, on your local machine
$ git branch coding_branch
add & add & commit commitmaster: c1 ----------> c2 ----------> c3 | | b| r| a| n| c| h| | v coding_branch: c3git branchUse the git branch command to create a copy of your repository, on your local machine
$ git branch coding_branch
Note that
git branchUse the git branch command to create a copy of your repository, on your local machine
$ git branch coding_branch
Note that
$ git branch -vgit branch — Notes add & add & commit commitmaster: c1 ----------> c2 ----------> c3 | | b| r| a| n| c| h| | add & add & v commit commit coding_branch: c3 ----------> c4 ----------> c5git branch — Notes add & add & add & commit commit commitmaster: c1 ----------> c2 ----------> c3 ----------> c5 | | b| r| a| n| c| h| | add & add & v commit commit coding_branch: c3 ----------> c4 ----------> c5git diffUse the git diff command to see what has changed, for changes
$ git diff
diff --git a/README.md b/README.md
...
--- a/README.md
+++ b/README.md
...
-1. Two times two makes five.
+1. Two times two makes four.
git diffUse the git diff command to see what has changed, for changes
$ git diff --staged
git diffUse the git diff command to see what has changed, for changes
$ git diff fdcb0ad
$ git diff HEAD~2
git diffUse the git diff command to see what has , for changes
$ git diff 241b728 1dfb2a5
$ git diff HEAD~1 HEAD~2
git diffUse the git diff command to see what has changed, for changes
$ git diff 241b728 1dfb2a5 README.md
$ git diff HEAD~1 HEAD~2 README.md
git diffUse the git diff command to see what has changed, for changes
$ git diff master..coding_branch
git checkoutUse the git checkout command to switch to
$ git checkout 241b728
$ git diff HEAD~1
git checkoutUse the git checkout command to switch to
$ git checkout 241b728 README.md
$ git checkout HEAD~1 README.md
git checkoutUse the git checkout command to switch to
$ git checkout coding_branch
9) Make sure there is nothing to commit in the master branch
git status command to see10) Make a new branch and switch to it
git branch and git checkout commands11) Start tracking the data/journals.csv file in this new branch
12) Commit the new version to this branch
13) Rename the first variable of the dataset, stage, and commit
name to journal_nameREADME.md and data/journals.csv14) Switch back to the master branch
15) Check the differences between the branches
git diff command07:30
git mergeUse the git merge command to integrate different versions of your repository into a single version
$ git merge coding_branch
add & add & commit commitmaster: c1 ----------> c2 ----------> c3 ------------------------> c6 | ^ | | b| |m r| |e a| |r n| |g c| |e h| | | add & add & | v commit commit | coding_branch: c3 ----------> c4 ----------> c5git mergeUse the git merge command to integrate different versions of your repository into a single version
$ git merge coding_branch
Note that
git mergeUse the git merge command to integrate different versions of your repository into a single version
$ git merge coding_branch
Note that
git checkout commandgit merge — Conflictsgit merge — Conflicts<<<<<<<< HEAD
1. Two times two makes five.
=======
1. Two times two makes tree.
>>>>>>>> new_branch
16) Merge the coding_branch into the master branch
17) Make a change on the same line of the README.md in both branches
18) Try to merge the coding_branch into the master branch
19) Solve the conflict and commit
07:30
git remote addUse the git remote add command to define a different place, to save an backup of your repositories
$ git remote add origin https://github.com/resulumit/git_workshop.gitgit remote addUse the git remote add command to define a different place, to save an external copy of your repositories
$ git remote add origin https://github.com/resulumit/git_workshop.git
Note that this includes
git_workshopgit remote addUse the git remote add command to define a different place, to save an external copy of your repositories
$ git remote add origin https://github.com/resulumit/git_workshop.git
Note that this line includes
git_workshoporigin, could also be anything elsegit pushUse the git push command to save a copy of your local repository to its remote repository
$ git push origin mastergit pushUse the git push command to save a copy of your local repository to its remote repository
$ git push origin master
Note that
git remote add commandgit pushUse the git push command to save a copy of your local repository to its remote repository
$ git push origin master
Note that
git pushUse the git push command to save a copy of your local repository to its remote repository
$ git push origin master
Note that
git pushUse the git push command to save a copy of your local repository to its remote repository
$ git push origin master
Note that
git pullUse the git pull command to get a copy of the remote repository, and merge it into the local repository
$ git pull origin mastergit pullUse the git pull command to get a copy of the remote repository, and merge it into the local repository
$ git pull origin master
Note that
git remote add commandgit pullUse the git pull command to get a copy of the remote repository, and merge it into the local repository
$ git pull origin master
Note that
git pullUse the git pull command to get a copy of the remote repository, and merge it into the local repository
$ git pull origin master
Note that
20) Add a remote repository
git remote add command21) Push the master branch to GitHub
git push command22) Commit a change to the README.md file on GitHub
23) Pull the changes to the local repository
git pull command07:30
There might be good reasons to exclude some others from versioning
for local-only repositories
paper.pdf, as opposed to paper.RmdThere might be good reasons to exclude some others from versioning
for local-only repositories
paper.pdf, as opposed to paper.Rmdfor repositories that are also on GitHub
files that contain information that we do not want others to see
files that we do not have the right to share with others
files that are too large
.gitignore.gitignore specifies which file(s) and/or folder(s) should be excluded from version control
.gitignore.gitignore specifies which file(s) and/or folder(s) should be excluded from version control
.gitignore lists one item per line
.gitignore.gitignore specifies which file(s) and/or folder(s) should be excluded from version control
.gitignore lists one item per line
See these
.gitignore — ExamplesYou can ignore, for example,
/manuscript/
.gitignoreYou can ignore, for example,
a specific folder, relative to the root directory
a specific file in a specific folder, relative to the root directory
/manuscript//manuscript/paper.pdf
.gitignoreYou can ignore, for example,
a specific folder, relative to the root directory
a specific file in a specific folder, relative to the root directory
a specific file in any folder
/manuscript//manuscript/paper.pdfpaper.pdf
.gitignore.pull-left[
You can ignore, for example,
a specific subdirectory, relative to the root directory
a specific file in a specific subdirectory, relative to the root directory
a specific file in any subdirectory
all files with a specific extension, anywhere in the repository
/manuscript//manuscript/journals.pdfjournals.pdf *.pdf
.gitignore — NotesThere are many other pattern formats
.gitignore — NotesThere are many other pattern formats
Starting to ignore a file or folder that is already being tracked requires clearing the cache
.gitignore, enter the following line in the shell/path/to/filegit rm --cached /path/to/file.gitignore — NotesThere are many other pattern formats
Starting to ignore a file or folder that is already being tracked requires clearing the cache
.gitignore, enter the following line in the shell/path/to/filegit rm --cached /path/to/file
The following command clears all cache
.gitignore that involves several files or foldersgit rm -r --cached .24) Create a .gitignore file on GitHub
25) Pull the changes to the local repository
git pull command26) Start tracking everything
27) Push the canges to the remote repository
.gitignore work as intended07:30
Settings -> Manage access -> Invite a collaborator
git clone command with the repository address$ git clone https://github.com/USER_NAME/REPOSITORY_NAME.git28) Prepare for collaboration
Owners:
Collaborators:
git clone command10:00
1) Pull
Pull to move the up-to-date records from GitHub to your computerAlready up-to-date.1) Pull
Pull to move the up-to-date records from GitHub to your computerAlready up-to-date.2) Edit and save; commit and push
29) Non-simultaneous Collaboration
.Rmd file, and/or on your GitHub repository05:00
29) Non-simultaneous Collaboration
.Rmd file, and/or on your GitHub repository05:00
30) Simultaneous Collaboration — Different Lines
10:00
30) Simultaneous Collaboration — Different Lines
10:00
31) Simultaneous Collaboration — Same Line
10:00
31) Simultaneous Collaboration — Same Line
10:00
1) Branch
git branch command to create a branch2) Edit and save; commit and push
3) Pull request
On GitHub, click
Pull requests -> New pull request
choose what is to be pulled, and write a note to your collaborator who can accept or reject the merge
32) Pull request
33) Merging
10:00
Integrating RStudio into the workflow requires
initial setup, done once*
project setup, repeated for every project
* We have started this process already, in Part 1 of the workshop, by downloading and installing Git and signing up for GitHub. Back to the relevant slide.
1) Enable version control with RStudio
Tools -> Global Options -> Git/SNV -> Enable version control interface for RStudio projects
RStudio will likely find Git automatically. In case it cannot, Git is likely to be at
c:/Program Files/Git/bin/git.exe on Windows
/usr/local/git/bin/git on Mac
2) Set Git Bash as your shell (Windows-only step)
Tools -> Global Options -> Terminal -> New terminals open with: Git Bash
3) Introduce yourself to Git
Tools -> Terminal -> New Terminal
git config --global user.name "YOUR-NAME" git config --global user.email "YOUR-EMAIL-ADDRESS"
git config --global --list
* This repeats the process on this slide in Part 3. Repeating it is unnecessary, but will not cause any problems.
1) Create an RStudio project
RStudio allows for dividing your work with R into separate projects, each with own history etc.
File -> New Project
2) Initiate local version control with Git
Tools -> Version Control -> Project Setup... -> Version Control System -> Git
2) Initiate local version control with Git
Tools -> Version Control -> Project Setup... -> Version Control System -> Git
after confirming your new repository, and restarting the session, observe that
now there is now a Git tab in RStudio, with buttons for various git commands
your project now includes a .gitignore file
3) Create a new GitHub repository
Repositories -> New -> Repository name (e.g., "git_workshop") -> Public -> Create repository
observe that
repository URLs have the following structure: https://github.com/USER_NAME/REPOSITORY_NAME
Terminal, the address gets the .git extension
3) Push an existing repository for the first time
Tools -> Terminal -> New Terminal
Terminal, with your username and repository namegit remote add origin https://github.com/USER_NAME/REPOSITORY_NAME.gitgit add .git commit -m "first commit"git push -u origin master3) Push an existing repository for the first time
Tools -> Terminal -> New Terminal
Terminal, with your username and repository namegit remote add origin https://github.com/USER_NAME/REPOSITORY_NAME.gitgit add .git commit -m "first commit"git push -u origin master
if this is your first time using GitHub with RStudio, you will be prompted to authenticate
observe that your project files are now online, listed on the GitHub repository
There are now two alternative ways to proceed
as opposed to in a stand alone shell
clicking the buttons on the Git tab
Blair, G., Cooper, J., Coppock, A., Humphreys, M., Rudkin, A. and Fultz, N. (2019). fabricatr: Imagine your data before you collect it. R package, version 0.10.0.
Resul Umit
post-doctoral researcher at the University of Oslo
interested in representation, elections, and parliaments
Keyboard shortcuts
| ↑, ←, Pg Up, k | Go to previous slide |
| ↓, →, Pg Dn, Space, j | Go to next slide |
| Home | Go to first slide |
| End | Go to last slide |
| Number + Return | Go to specific slide |
| b / m / f | Toggle blackout / mirrored / fullscreen mode |
| c | Clone slideshow |
| p | Toggle presenter mode |
| t | Restart the presentation timer |
| ?, h | Toggle this help |
| Esc | Back to slideshow |