<style> .reveal { font-size: 30px; } </style> ## Reproducible Research: Git <!-- Put the link to this slide here so people can follow --> link: https://hackmd.io/@WHardy/rr-git main source: Krzysztof Kość's [materials]( http://coin.wne.uw.edu.pl/kkosc/02_Git.html#/git-intro-1) --- ## Before we start: system check! 👷 - Version check (cross-platform): - `git --version` ---- #### Installation - Linux: - `$ sudo apt install git-all` - Windows: - Download and install [Git for Windows](https://gitforwindows.org/) - macOS: - `$ xcode-select --install` if you don't have Xcode - `$ brew install git` using Homebrew --- ### Git rationale :::info Let's assume that you are working with a colleague on a project: - What if you edit the same files (file conflicts)? - What if you want to revert to the earlier stage (errors...)? ::: --- ### We need a tool that: - Split work of people into increments, manage merges and conflicts - Have one predefined source of truth, e.g. a repository on a server - Minimise the interactions between the users as much as possible --- ### What’s a version control system (VCS)? - VCS tracks the history of changes as people and teams collaborate on projects together - Teams can run tests, fix bugs, and contribute new code with the confidence that any version can be recovered at any time - Developers can review project history to find out: - Which changes were made? - Who made the changes? - When were the changes made? - Why were changes needed? - See: [Git handbook](https://guides.github.com/introduction/git-handbook/) --- ### GIT basics - Open source distributed version control system - Unlike once popular centralized VCS, DVCSs like Git don’t need a constant connection to a central repository - Created in early 2000's by Linus Torvalds during work on Linux kernel project - Moderately difficult to learn, very difficult to master - Became so popular that it effectively replaced older tools (svn, mercurial, svc) ---- ### Popularity of different VCS among developers ![](https://i.imgur.com/QIahk7i.png =600x350) *Source*: [Stackoverflow, *Developer Survey Results 2017*](https://insights.stackoverflow.com/survey/2017#technology). [Unfortunately, they discontinued asking that question in the following editions] ---- ### Popularity of collaboration tools among devs ![](https://i.imgur.com/8niYUUc.png =600x350) *Source*: [Stackoverflow, *Developer Survey Results 2020*](https://insights.stackoverflow.com/survey/2020#development-environments-and-tools) [44,328 responses, select all that apply] --- ### Git trivia ![](https://i.imgur.com/5lxNWrc.png =450x) *Source*: Urban Dictionary. - Git replaced the older solutions because the latter were even worse... - ... and it's flexibility helps to use more modern project workflows (scrum/agile, etc) - Git has both CLI and visual plugins in many IDEs - :warning: We will test them during our course! --- ### Git 101 <!-- .slide: style="font-size: 24px;" --> - **repository**: the entire collection of project's files and folders;</br> along with each file’s revision history - **commit**: basic unit of work (circle) - **branch**: set of units of work (downward line) - **checkout**: create new branch (left arrow) - **merge/rebase**: join branches (right arrow) - **master**: the main repo branch (production branch) - **origin**: the remote repo (e.g. stored on github) ![](https://i.imgur.com/OExHiqg.png =200x) --- ## CLI vs GUI - Today we will work with Git using its CLI git bash to become familiar with basic commands ![](https://i.imgur.com/x14KPPC.png =250x) *Source*: [XKCD](https://imgs.xkcd.com/comics/git.png). --- ![](https://i.imgur.com/I7qIgm9.png) --- ![](https://i.imgur.com/Br6mxqX.png) - `git rebase` vs `git merge`: https://www.atlassian.com/git/tutorials/merging-vs-rebasing --- ## Exercises! 🏋️‍♀️ --- ## Exercise 0: configuration - `git config -l`: view all configuration options - config structure: `git config [-l] [--scope] [option_name] [value]` - By default, git config will write to a local level: `--local` - Global level configuration is user-specific: it is applied to an operating system user: `--global` - There is also a `--system` level ---- 1. List all available options, then list all global options, then list all local options ---- `git config -l` `git config -l --global` `git config -l --local` ---- 2. Set global option 'user.name' to your name ---- `git config --global user.name "Name Surname"` ---- 3. Set global option 'user.email' to your e-mail ---- `git config --global user.email "mail@example.com"` ---- 4. List all global options, check the difference ---- `git config -l --global` ---- 5. Set local option 'user.name' to your initials ---- `git config --local user.name "MP"` ---- 6. List all local options, check the difference ---- `git config -l --local` --- ## Exercise 1 1. Create a working directory for your git projects (e.g. ./workspace) ---- `mkdir git_workspace` ---- 2. In this directory, create directory myFirstRepo and go inside it ---- `ls` `cd git_workspace` `mkdir myFirstRepo` `cd myFirstRepo` ---- 3. Check the status of git repository (should be none), then initialise a new repository and check status again ---- 4. Create a file named README.md, add a single line of text inside, save the file ---- `echo This is my Readme file > README.md` ---- 5. Stage and commit the file, check git log --- ## Exercise 2 0. Use repository from the previous exercise 1. Modify contents of the README.md file by adding another line of text ---- `echo This is a next line of text >> README.md` double pipe '>>' means append to file ---- 2. Check repository status, then check what has changed since the last commit (snapshot) ---- 3. Add directories src and data, check status and diff ---- 4. Create data/data1.csv file and fill it with random data line, check status and diff ---- `touch data/data1.csv` touch is yet another method of creating empty files `echo -e "Key,Val\n1,5" >> data/data1.csv` ---- 5. Create .gitignore file, put name of data directory inside, check status and diff ---- 6. Stage the files and commit them, remember to write an useful commit message --- ## Exercise 3 1. Exit to the main repository workspace ---- 2. Clone myFirstRepo name it client1 ---- `git clone myFirstRepo/ client1` ---- 3. Check the contents of the newly cloned repo ---- `cd client1` `ls -ltha` ---- 4. Inside the cloned repo, check the config file hidden in .git directory ---- 5. Compare this file with .git/config file from original repository ---- `diff .git/config ../myFirstRepo/.git/config` just 'diff' command is a system command, do not mistake it with 'git diff'! ---- 6. Return to the myFirstRepo directory, list all branches (-la option) ---- 7. Create a new branch named e.g. feat/downstream ---- 8. Checkout the newly created branch, add a new source code src/fun-do_nothing.R file with a dummy R function ---- 9. Stage and commit the changes, return to the client1 repo --- ### Sources & Further reading - Krzysztof Kość's materials: http://coin.wne.uw.edu.pl/kkosc/02_Git.html#/git-intro-1 - [How not to be afraid of GIT anymore](https://www.freecodecamp.org/news/how-not-to-be-afraid-of-git-anymore-fe1da7415286/) - [How to use git and not to go crazy (in PL)](https://kamiljozwiak.net/gitflow-czyli-jak-korzystac-z-gita-i-nie-zwariowac/) - [Github Guides: Git Handbook](https://guides.github.com/introduction/git-handbook/) ---
{"metaMigratedAt":"2023-06-15T20:39:18.505Z","metaMigratedFrom":"YAML","title":"Reproducible Research - GIT","breaks":true,"slideOptions":"{\"transition\":\"slide\"}","contributors":"[{\"id\":\"1c10bb23-6c4c-4c1b-8586-5f8d56305139\",\"add\":8243,\"del\":491}]"}
    204 views