Tim Dennis
    • 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

      This note has no invitees

    • Publish Note

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

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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
    • Note Insights New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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

    This note has no invitees

  • Publish Note

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

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: "Excercises for GIT" tags: git --- ## Create a Repository 1. Login to GitHub: https://github.com/ 1. On https://github.com/ click on the + button, top right corner 2. Name the repository "hello-world" 3. GitHub will ask if you want to add a README.md, license or a .gitignore file. Do not do any of that for now. --- ## Undoing Commits & Changes * What questions are there from the first part? * Ok, let's look at the state of our repo ``` git status ``` ``` git log ``` * Who can tell me what these long numbers are? * We can also control the behavior of git log with a flag * I like this one: ``` git log --oneline ``` * Especially useful when you have lots of commits * You can get real fancy & granular with your git log <https://www.atlassian.com/git/tutorials/git-log> * Let's add a guacamole recipe to our `index.md` * Now I'm going to use a built-in command line editor called `Nano` to edit this file * You should have it as well if you installed the workshop tools * If you are having issues, you can also use your default text editor, **Notepad** on win, and TextMate on mac ``` nano index.md ``` ``` Lets add: ## ingredients * 2 avocados * 1 lime * 2 tsp salt ## instructions * chop avocados * chop onion * squeeze lime * add salt * and mix well ``` ``` git status ``` ``` git diff ``` * How do we commit our changes locally? * Right `git add, git commit` cycle ``` git add guac.md ``` * What's a good commit message here? ``` git commit -m 'adding guacamole recipe' ``` ``` git status ``` * One metaphor that works for me for this `edit`, `add`, `commit` process is taking a photo, let's look at this diagram: ![snapshot](https://i.imgur.com/QOrgxYZ.png) ``` git log --oneline ``` * Let's introduce something we don't like in guac. * You can pick your own ingredient that you don't like in guacamole. * I'm using tomato. ``` nano index.md ``` * I'll add tomato * `ctr+x` and save and exit ``` git add index.md git commit -m "adding tomato to guac" ``` ``` cat index.md ``` * We can also look at our log ``` git log --oneline ``` * **But turns out**, I **hate tomato** in my guac and don't know why I add it! Yuck. * I want to undo this change * To undo this in Git like with most things there are a number (prob too many) ways to go about it * We'll use the `git revert` command today, which has some benefits when working with public repos in github * Other ways to do include`git checkout``git reset` (I'll share a table shortly) * When we run the git-revert command it will pop you into your default text editor (nano for me) where you can add a message - I will accept the default message, but you can add more. ``` git revert HEAD ``` * We didn't talk about HEAD yet * Do you have any intuition about what it means? * You can think of it as a tag or keyword for the current state of your repository (the branch it is in and commit it is on) * You can read this as 'undo this last change I made' * `git revert` also creates a commit which undoes changes made in a given commit, creating a commit which is reverse of a given commit * This is important b/c it creates a record of what you did for your collaborators rather than just undoing something without that history. * `git revert` is recommended when you are working with public repositories in github or gitlab * We can look at the file now ``` cat index.md ``` * There are other ways to go back in your timeline of commits, think of this is a timeline slider * For insatnce, `git reset fc83262` will undo all the changes back to that commit (we get the hash from oneline log) * If you want to rewind back to a specified commit, and you can use this because this part of history was not yet published, you need to use git-reset, not git-revert: * `git checkout sha-hash` will take you back to the state of the commit * Here's a table of some ways to undo: **More ways to undo thing** | Git command | Description | Example | | -------- | -------- | -------- | | `git checkout` | Switch branches or restore working tree files | `git checkout <sha hash>` | | `git reset` | Reset current `HEAD` to the specified state | `git reset fc83262` | | `git clean` | Remove untracked files (ones not added yet) from the working tree | `git clean` *deletes files permanently!* - add `-n` or -dry-run to preview | | `git revert` | Revert some existing commits | `git revert HEAD~2` | Anybody know what the `~2` means above? See this for more: <https://www.atlassian.com/git/tutorials/undoing-changes> >The **HEAD** in Git is the pointer to the current branch reference, which is in turn a pointer to the last commit you made or the last commit that was checked out into your working directory. That also means it will be the parent of the next commit you do. It's generally simplest to think of it as HEAD is the snapshot of your last commit. The tilde operator acts as a minus on HEAD, so HEAD~1 goes back one commit from head, HEAD~2 two, and so forth. * That was a lot! There are even more ways to undo and move around the timeline of your changes. * The great thing about Git is it gives you a lot of ways to go back in time (downside is, it is overwhelming) * I personally don't try to create situations where I need to roll back changes :smile:, but when it happens (and it will), if my stuff is under version control, there are many ways I can recover my previous state. * Since I'm not actively involved in a code project in git, I don't keep these commands in my head. I search for how to do this stuff typically everytime I use. * Further, if I commit early and often in distinct bundles of work (changes that hang together), I have a lot of granular power on what I can roll back too. * What questions are there? add a space in etherpad and wait 2 min ## GitHub Pages An intro: <https://docs.google.com/presentation/d/1NN41MIPEwZ6ZnfU14EHuGcHxwo05JCtExtaRw2eVAKU/edit#slide=id.gb94cd5090f_2_0> * we learned alot in the last section. **The gh-pages branch** GitHub Pages uses a special branch in your GitHub repository to look for website content, and by default this is the branch with the name ‘gh-pages’. You can actually change this, under repository settings, to use for instance the master branch instead, but let’s stick with the default for now. It’s possible to create a new branch directly on GitHub, but we will use the command line now. So we will move back to the command line and type ``` git checkout -b gh-pages git push fatal: The current branch gh-pages has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin gh-pages ``` * let's follow what the message tells us to do ``` git push --set-upstream origin gh-pages Total 0 (delta 0), reused 0 (delta 0) To https://github.com/danmichaelo/hello-world.git * [new branch] gh-pages -> gh-pages Branch gh-pages set up to track remote branch gh-pages from origin. * Ok, let's push up our chages ``` * Let's look at a diagram of what we just did <https://photos.google.com/u/2/search/diagram/photo/AF1QipMw45TxeOp8hDN6MN-FimHznItUikclT3HHrDCN> * This is from the first git workshop I took in the Carpentries! * Let's go take a look at github now <https://github.com/> --- ## Tour of GitHub - Repo view 1. Code - where your files and folders live 2. Click on commits and notice you previous commits (versions), 3. To the right you can click on the copy symbol and this copies the hash that represents that version 4. You can click on the alphanumeric digits (28f2aaa) to see the changes incorporated at that commit 5. You can browse (go back to the previous state) by clicking < > --- ## Now, let’s explore our new repo 2. Issues - important way we communicate in GH (a feature in GitHub, not in Git), let's fire an issue Click 'New Issue' and add a note about something that needs to get done or a problem 3. Pull Requests - these are suggestions for change from forked repositories waiting to be merged or commented on (we will come back to this) 4. Projects - you can use GitHub as PM tool 5. Wiki - some projects use to document their work 6. Insights - metrics on your repository 7. Settings - this is where you can add collaborators -- great if you work with defined teams. --- ## A brief tour of our profile 1. Top right drop down - see you can be parts of organizations, look at your profile 2. Show profile 3. Show Organizations 4. Stars 5. What gist is --- --- ## Challenge: Contributing to a page owned by someone else (slightly easier way) To practice using Git, GitHub pages and Markdown we can contribute to a GitHub pages site. Pair up in groups of two (or more if needed) and do the exercises below together. 1. Introduce yourself in your group! Name, affiliation, area of study. 2. Trade the url to your `hello-world` repository on GitHub with your partners. 3. Go to your partner's repository. It should be something like https://github.com/some-librarian/hello-world, where "some-librarian" is the username of your exercise partner. 4. Click on "Fork" in the upper right part of the screen to create a copy of the repository on your account. Once you have a fork of your partner's repository, you can edit the files in your own fork directly. 5. Edit `index.md` and **add your favorite ingredient** not mentioned in guacamole & update the instructions 6. Click the "index.md" file, then click the edit pencil icon: ![GitHub edit pencil](https://librarycarpentry.org/lc-git/fig/github-edit-pencil.png) 4. Now is good chance to try some Markdown syntax. We've been using some already! Try some of the examples at [Mastering Markdown](https://guides.github.com/features/mastering-markdown/). You can preview how it will look before you commit changes. Try adding an image or linking to an outside site. 5. Once you are ready to commit, enter a short commit message, select "Create a new branch for this commit and start a pull request" and press "Propose file change" to avoid commiting directly to the gh-pages branch. ![Commit and create pull request](https://librarycarpentry.org/lc-git/fig/github-commit-pr.png) 8. You can now go to the repository on your account and click "New Pull Request" button, where you can select base branches repositories, review the changes and add an additional explanation before sending the pull request (this is especially useful if you make a single pull request for multiple commits). 9. Your partner should now see a pull request under the "Pull requests" tab and can accept ("Merge pull request") the changes there. Try this. This whole process of making a fork and a pull request might seem a bit cumbersome. Try to think of why it was needed? And why it's called "pull request"? > ## Solution > We made a fork and a pull request because we did not have permission to edit > (or commit) the repository directly. A fork is a copy of the repository that > we *can* edit. By making a pull request we ask the owner of the repository if > they would like to accept (pull in) the changes from our fork (our copy) into > their version. The owner can then review the changes and choose to accept or > reject them. > > You can open pull requests on any repository you find on GitHub. If you are a > group of people who plan to collaborate closely, on the other hand, > it's more practical to grant everyone access to commit directly instead. > ## Optional challenge: Contributing to a page owned by someone else (slightly more complicated way) Instead of making edits on the GitHub website you can 'clone' the fork to your local machine and work there. Try following the rest of the steps under "Time to Submit Your First PR" at this guide: <https://www.thinkful.com/learn/github-pull-request-tutorial/Writing-a-Good-Commit-Message#Time-to-Submit-Your-First-PR> (If you followed step 1 and 2 in the previous challenge, you already have a fork and you can skip the creation of a new fork if you like. You can submit multiple pull requests using the same fork.) --- ## Fork and Create a PULL REQUEST practice (larger scale) 1. Go to this repository I made: https://github.com/ucla-data-archive/git-collaboration 2. Click on the 'fork' - this will make a copy of my repo into your account - notice how they are linked 3. Inside the countries folder, edit one country and provide the information needed 4. Add a commit message and save. 5. Navigate to the repository home page, you should see a note above the files "This branch is 1 commit ahead of jt14den:master." with a "Pull Request" link towards the right. 6. Click on the "Pull Request" and then 'Create pull request button" - leave a short message and add to it if you need to say more, then "Create pull request" 7. This will send a message to me (the owner of the repository you forked from), that you have changes you want me to incorporate in my repository. 8. I'll merge your changes, initiate a discussion about your changes, or resolve conflicts if needed. 9. This is how changes and improvements are incorporated in the Carpentries and most big coding projects --- ## Uses of Git - Helpers Can Join in here * Make a place on the etherpad for different uses of github or other hosted git tools or git itself * you talk about a few favorites: * Awesome Lists - Curated list of resources on topics (mostly technical) * I look for datasets on <https://github.com/awesomedata/awesome-public-datasets> * Gitenberg - the books from Progject Gutenberg * a collaborative, trackable, scriptable digital library using Git * All the Carpentries lessons (you can click on the Repository icon to get to the github repo) * Data Carpentry https://datacarpentry.org/lessons/ * Software Carpentry https://software-carpentry.org/lessons/ * Library Carpentry https://librarycarpentry.org/lessons/ * OpenGeoMetadata - a project share geo metadata & discovery * https://github.com/OpenGeoMetadata

    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
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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