WHardy
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- title: Reproducible Research 5 - Git 4 tags: RR2023 - DS/QF description: slideOptions: # theme: solarized transition: 'slide' --- <style> .reveal { font-size: 26px; } </style> ## GitHub Wojciech Hardy link: https://hackmd.io/@WHardy/RR-git4 --- ## Let's take a look at GitHub [github.com](https://github.com/) --- ## Notably, it's not only GitHub [GitHub](https://github.com/) - think: Microsoft, tons of repositories managed remotely, mostly for open repositories. [GitLab](https://about.gitlab.com/) - think: DevOps and CI/CD. ![](https://about.gitlab.com/_nuxt/image/cbdd4f.svg =500x) [Atlassian's BitBucket](https://bitbucket.org/product) - think: private firm solutions and Jira. Etc. We'll use GitHub as an example. --- ### Working with GitHub There's several ways you can interact with GitHub. Let's cover a few cases: 1) Start with a GitHub repository, create a local version. 2) Start with a local repository, put it on GitHub. 3) Fork someone's repository on GitHub, create a local version, grab updates from the original version. 4) Use GitHub Desktop (or another tool) 5) Run an RStudio project connected to GitHub. [Happy Git With R has nice step-by-step guides - not only about R and GitHub. Check it out.](https://happygitwithr.com/) --- ### Password, authentication, etc. We might have to go through some connection issues on our first go. Here's a [good reference](https://happygitwithr.com/https-pat.html). In principle, Git might ask you for authentication when you first connect with GitHub from your computer. It might be enough to log in via browser. But if it asks for username and password, note that the 'password' might refer to a **Personal Access Token**. **How to generate one?** On GitHub, go: Account settings -> Developer settings -> Personal Access Tokens -> Generate new token. Check `user`, `workflow` and `repo` and it should cover most basic usage. Copy the token and place it in the prompt instead of the password. --- ### Case 1. GitHub to local 1. Go to GitHub and create a new repository. Click the ![](https://i.imgur.com/omKOgl6.png) button at GitHub. Let's start with a `Readme.md` file (check the relevant box). This will initiate a non-empty repository. ---- 2. Copy the HTTPS URL. At your Repository, click the green **code** button and copy the HTTPS URL. Example: ![](https://i.imgur.com/jrTDE0h.png) ---- 3. Prepare some space (a folder) for your repository and clone it. `mkdir repositories` `cd repositories` `git clone <copied_url>` ---- 4. Do some checking (e.g.: `cd MyRepoName` `ls` `git status` `head README.md` `git remote show origin` ) ---- 5. Create a simple `.txt` file. Stage it, commit it, put it back in the remote repository. `echo "some text" > hello.txt` `git add hello.txt` `git commit -m "Added a hello.txt file"` `git push` Note\: this might be the moment when you run into an authentication request. ---- 6. Check the repository on GitHub. Refresh the page. Your hello.txt file should appear. --- ### Case 2. Local to GitHub 1. Create a new repository on your local machine. `cd ..` `mkdir Ex2Repo` `cd Ex2Repo` `git init` ---- 2. Create a simple `.txt` file. Stage it and commit it. `echo "some text" > hello.txt` `git add hello.txt` `git commit -m "Added a hello.txt file"` ---- 3. Go to GitHub and create a new (empty!) repository. Click the ![](https://i.imgur.com/omKOgl6.png) button at GitHub. Don't start with any of the standard files! You will then initiate a repository without a commit history (avoidng a conflict of two unrelated commit histories). ---- 4. Copy the clone URL. At your bare repository, click the green **code** button and copy the HTTPS URL. Example: ![](https://i.imgur.com/jrTDE0h.png) ---- 5. Set up a connection with the remote repository. `git remote add origin <copied_url>` ---- 6. Push your repository contents. `git branch -M main` will rename the `master` branch to `main` `git push -u origin main` Note\: you have to set the upstream for your branch (you can also do it with --set-upstream) --- ### Case 3. Forking and getting updates 1) Choose an existing GitHub repository (someone else's!) and fork it. Example (press the "Fork" button): ![](https://i.imgur.com/hNVpKYC.png) ---- 2) Clone the fork to a local repository. Repeat Case 1 steps for your new repository. ---- 3) Doing pull requests In your local repository create a new file, stage it, commit it and push it. In GitHub you should see you're '1 commit ahead'. Try opening a pull request (you don't need to follow through). ---- 4) If there's an edit to the repository you forked -> execute a pull We need to establish a link: a) Check the configured remote repo. `git remote -v` b) Add a path to the forked remote repo. `git remote add newUpstream <copied_url>` c) Check again. `git remote -v` ---- 5) Fetch the information from the new upstream. `git fetch newUpstream` ---- 6) Merge with the new information. Then push it back to your GitHub repository. `git merge newUpstream/main` --- ### Case 4. Using e.g. GitHub for Desktop [![](https://i.imgur.com/19hLLqL.png =250x)](https://desktop.github.com/) 1. Install and log in. 2. Try replaying what you did in previous cases: - clone a repository from GitHub. - put a local repository on GitHub. - check how to stage, commit, push, pull, merge, etc. (it's just clicking on names you already know). --- ### Case 5. Using GitHub with RStudio 1. Open RStudio. 2. Create a new project with version control (Git). File -> New project... -> Version control -> Git 3. Use the URL for one of your repositories at GitHub. 4. Check how to stage, commit, push and pull. You should now have a "Git" tab in top-right corner. Check it out. 5. Use the terminal for more nuanced operations. You can use the terminal the same way you used Bash. --- ### ASSIGNMENT 1. 1. Register at GitHub (or use an existing account). 2. Fork the [course repository](https://github.com/WHardyUW/RRcourse2023). 3. If your GitHub nickname allows me to identify who you are in USOS, move to point 4. If not, please send me an e-mail to let me know who you are at GitHub - thanks! 4. Clone the repository so you can work on it locally (use the option you prefer). 5. Go to the "5. RR_git4" (i.e. the directory for today's classes) and edit the `hello.txt` file inside (e.g. write the date inside, or smth). 6. Stage the change, commit it and **push it**. That's it. That's the assignment. --- ## Contributing to another repository Sometimes you'll want the owner of the original repository to include your changes. E.g.: 1) you think you've upgraded the original project. 2) you're part of a team and the process of updating a central repository involves reviews, etc. Go to your forked repository. You should see the information that you're ahead of the repository that you forked. --- ## ASSIGNMENT 2: Initiating a pull request In your repository you can grab the changes from its source. But you can also try to pass your commits to it. You can do so through the pull requests tab or by clicking the `contribute` button. Do it now with the course repository.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully