tingtinghsu
    • 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

      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
    • Note Insights
    • 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 Note Insights 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

    This note has no invitees

  • 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: Git 7.10 Github tags: Git, 5x --- 7.10 0506 Github === # GitHub簡介 大部分的Git操作都是在電腦完成 若要跟別人共同協作,有Git伺服器會比較方便 GitHub = 一款有Web介面的Git伺服器 GitLab BitBucket 優點: 1. 跟厲害的開發者們交朋友 2. 開發者最好的履歷 # 開新專案 New repository,網頁版右上角 `+` ## 全新專案 ``` …or create a new repository on the command line echo "# 5x-demo" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/tingtinghsu/5x-demo.git git push -u origin master ``` 如果選擇`https`,`https://github.com/tingtinghsu/5x-demo.git` 在推送的過程中會需要輸入帳號密碼 如果選擇`SSH` ,git@github.com:tingtinghsu/5x-demo.git ## 現成專案 ``` /*設定一個遠端節點*/ git remote add origin /*origin節點名字可以自己取*/ https://github.com/tingtinghsu/5x-demo.git /*把本機的master推到遠端*/ git push -u origin master ``` ### 在source tree設定 Repository -> Repository Settings... -> Remote name: origin URL/Path: https://github.com/tingtinghsu/5x-demo.git ``` tingdeAir:git-rebase tingtinghsu$ git push -u origin master Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 440 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), completed with 1 local object. To https://github.com/tingtinghsu/5x-demo.git 647145b..6cc2c94 master -> master ``` # remote相關的git指令 ## git remote `git remote add origin` + 某個網址 * 新增一個叫做origin的遠端節點,這個節點會指向某個網址 * `origin`可以代換為別的名字 ## git push `git push origin master` * 要把本地的master分支,推往origin這個遠端節點,並且在遠端形成一個master分支 * 當遠端節點的版本比較新的情況,使用`git pull`或`git fetch` ## `git pull` vs `git fetch` git fetch: 跟remote比對,將local沒有的檔案拉下來 git pull: `git fetch` + `git merge` ## git fetch `git fetch origin master` * 去`origin`這個遠端節點,抓上面`master`分支的內容,並且在我的電腦上建立一個`origin/master`分支 ### 在CL ``` tingdeAir:git-rebase tingtinghsu$ git merge origin/master Updating 6cc2c94..ea6fdcd Fast-forward index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) ``` ### 在source tree 在origin/master上按右鍵 -> `merge` -> Are you sure you want to merge `origin/master` into your current branch? -> 確定 * `master`的貼紙移動到`origin/master` * 合併分支就是在移動貼紙 ## git pull `git pull origin master` * 去`origin`這個遠端節點,抓上面`master`分支的內容,並且在我的電腦上建立一個`origin/master`分支 * 同時與我本機的master分支進行合併 ## git clone + `某個Git網址` * 要把某個git網址的內容,整個複製一份到我的電腦裡 ``` tingdeAir:~ tingtinghsu $ git clone https://github.com/tingtinghsu/learn-ruby-on-rails.git Cloning into 'learn-ruby-on-rails'... remote: Enumerating objects: 692, done. remote: Total 692 (delta 0), reused 0 (delta 0), pack-reused 692 Receiving objects: 100% (692/692), 9.94 MiB | 1.76 MiB/s, done. Resolving deltas: 100% (369/369), done. Checking connectivity... done. ``` ## 練習 1. 在Github上建立一個Repository 2. 把之前在本機上練習的檔案,推一份到這個新建的Repo裡 3. 直接在Github上對某個檔案進行編輯並存檔 4. 使用fetch或pull指令,把剛剛的更新抓下來 # 在Github 跟其他人一起工作 有時候同事更新比較快,會遇到推不上去的情形 ## 狀況. A先push到master,B要push到master的時候,推上不去 ### 1. 使用 `git pull` `git pull --rebase`的使用時機 因為`git pull`包含使用`git merge`功能,會讓兩者合併時產生新節點。 如果再加上`--rebase`,會先把遠端的進度拉一份下來接在後面; 再接自己本地的進度接在後面;看起來像是無縫接軌。 ### 2. 使用 `git push -f` `--force` 推上前,先知會大家要以自己的版本為主。 ## 3. 使用 PR (Pull Reqest) * 開自己的分支撰寫程式,避免跟別人的版本打架 * 就不用每次push前先pull 方法: 1. 先`fork`專案到自己的帳號下 2. 寫好後提出`pull request` 專案擁有者`merge pull request`時,選擇 `rebase and merge`選項,不會造成合併的節點,可以讓歷史記錄比較乾淨 # 0701 實體課程 - Github ## git push origin master的解釋 ``` Git push origin master 把master的進度推一份到origin Git push origin master Git push abc master Git push xyz master Git push heroku master Git remote add heroic git@heroku.com:tingtinghsu Git push piano master (把貓推到鋼琴上) ``` ``` git push origin master => git push origin master:master (遠端建立master branch的意思) 所以 git push origin master:cat (遠端建立cat branch的意思) ``` 會用到`git push origin master:cat`的情境 ``` git push heroku master (heroku只能接受推master) git push heroku dev git push heroku dev:master (dev推上heroku遠端節點,再把遠端推成master branch的意思) ``` ```  git push origin master:cat Total 0 (delta 0), reused 0 (delta 0) remote: remote: Create a pull request for 'cat' on GitHub by visiting: remote: https://github.com/tingtinghsu/gitfile/pull/new/cat remote: To github.com:tingtinghsu/gitfile.git * [new branch] master -> cat ``` ## 1. 在GitHub建立新專案 Github按左上角的`(+)` 參考https://hackmd.io/X82JI7apT5mr6Gp3q4OnFg#%E9%96%8B%E6%96%B0%E5%B0%88%E6%A1%88 ## 2. 在本地電腦產生SSH Key ```  ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/tingtinghsu/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/tingtinghsu/.ssh/id_rsa. Your public key has been saved in /Users/tingtinghsu/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Iq4xYSKyLdY27bThg4cZM+RZTPb+BhYj9TOT8jbLl2s tingtinghsu@Hui-TingdeMacBook-Air.local The key's randomart image is: +---[RSA 3072]----+ | | | o . | | + o . . | | . + = * | |+ = + + S + | |o=.O.. = + | |o.++O+. = o . | |...B=oo = E | | . .+. . o.. | +----[SHA256]-----+ ~  cd /Users/tingtinghsu/ ~  ls Applications Documents Dropbox Movies Pictures Desktop Downloads Library Music Public  ~  ~/.ssh ~/.ssh  ls id_rsa id_rsa.pub known_hosts ~/.ssh  code . ~/.ssh  cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDVr2bi2kTesH5q1qbs0kx2rlWjCV5poV87HI5d8J0WQXXEt5oRCEi3+TP1UklablEGTD2zRjIBLkzN7AIZadALzkFMdfyLT7Y8b1ll5kDc3lNyb6mCHfqjUe5XAWit2oVUS1zqaCbcBdRUvEmxR0vprO3ksaCPbHbYDkaK7lkq/rPgfGwMXVz1FHjj7vD4x7v1NcQnAyw0ZyGgV9/VeYs7eCILHdRXpAbstmFDyXcHYJwVgnRbEh0B4cCJ4/489sVsucZNgH/FghAOYAdX864I0OtNu44xBGyafauU2hOFgkxcRaio4Y09eUUD8IoEDmErShL/QT64ZJnxdG3sfswik3TvKuQWmbWn4CKN9Vxx0+1esg9dUgY7wjfDvhPgssEDmLp5ZLDy1PLhNf7uflSWmzwhrfa9XmNPW+X8ijpHwJSmfaKDvPaB78yNg9O3avjV6IMJW7FaV1tqqQyp9XLDpOnH180KMTNZjV68yUE+Jd11n6IJR0xy8J8WK04XkfE= tingtinghsu@Hui-TingdeMacBook-Air.local ``` ## 3. 為GitHub設定SSH 1. 確定該資料夾是否有設定遠端: `git remote -v` ``` fatal: not a git repository (or any of the parent directories): .git (要選擇有.git檔案的資料夾才可推) ``` 2. 移除設定推送的遠端位置: `git remote rm origin` 3. `-u` 設定預設的本地與推送的遠端位置配對 (看你最近在忙什麼專案) `git push -u origin master` 註:如果沒有`-u`,每次`git push`會出現 `The current branch master has no upstream branch.` ``` git push origin master The authenticity of host 'github.com (140.82.114.3)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'github.com,140.82.114.3' (RSA) to the list of known hosts. Enumerating objects: 9, done. Counting objects: 100% (9/9), done. Delta compression using up to 4 threads Compressing objects: 100% (7/7), done. Writing objects: 100% (9/9), 899 bytes | 299.00 KiB/s, done. Total 9 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), done. To github.com:tingtinghsu/gitfile.git * [new branch] master -> master git push fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use git push --set-upstream origin master ``` ``` ~/Documents/projects/gitdemo   master  git remote add origin git@github.com:tingtinghsu/gitfile.git ~/Documents/projects/gitdemo   master  git remote -v origin git@github.com:tingtinghsu/gitfile.git (fetch) origin git@github.com:tingtinghsu/gitfile.git (push) ~/Documents/projects/gitdemo   master  git push origin master The authenticity of host 'github.com (140.82.114.3)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'github.com,140.82.114.3' (RSA) to the list of known hosts. Enumerating objects: 9, done. Counting objects: 100% (9/9), done. Delta compression using up to 4 threads Compressing objects: 100% (7/7), done. Writing objects: 100% (9/9), 899 bytes | 299.00 KiB/s, done. Total 9 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), done. To github.com:tingtinghsu/gitfile.git * [new branch] master -> master ```

    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