jamie224
    • 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
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    <div style="text-align:right;"><h6>2023/3/20</h1></div> # <center>GitHub 學習筆記 (二) push to GitHub</center> ### <center> (二) 如何把現有的 repository push 到 git hub 上 </center> #### <center> Git - pushing an existing repository </center> --- ## **++前情提要/事前準備++** >距離上一次筆記居然已經過了一個月,要督促自己好好學習,不能3分鐘熱度QQ ### **++Step 1 - 在 Github 上開新專案++** #### **++新增一個 new repository++** 要把檔案上傳到github,首先要先在上面開一個專案 (repo)。請在Github主頁右上角點選「+」號,並選擇「New repository」: ![](https://i.imgur.com/bmmyK3x.png) 這裡可以自己設定repository,也可以選擇要設定為**公開還是私人**的,非常方便! (2019年初開始,GitHub 免費版的也可以設定為私人了) ![](https://i.imgur.com/HvUhSVB.png) 同一個頁面當中,也可以選擇是否直接在生成 repository 的時候**自動生成 README file**。 ![](https://i.imgur.com/FCFoYjw.png) ### **++Step 2 - 初始化自己的Git Folder++** 進入自己要上傳的資料夾檔案目錄下: #### **++初始化 Git Repo++** ``` git init ``` 在這個步驟會在根目錄下建立一個隱藏的.git資料夾,讓 git 可以識別並且用它來儲存版本歷史等等資訊。 #### **++把檔案加入到git的暫存區++** ``` git add -A ``` 這裡的 '-A'代表 include all,會把所有根目錄下的資料夾都放到暫存區,如果有部分檔案沒有要上傳到 github 上,可以用 (如果同步要刪除 local 端的檔案就把 --cached 拿掉): ``` // Remove directory from Git but NOT local git rm -r --cached 'myFolder/myFile' git commit -m "Removed folder/file from repository" git push origin <your-git-branch> ``` 再來用 git status 確認: ``` git status ``` 可以發現上一步 add 的檔案因為還沒有commit所以會被提醒 ![](https://i.imgur.com/op0pdk8.png) #### **++Commit 加入的檔案++** ``` git commit -m 'push existing project' ``` "-m"代表 message,後面的字串可以用來表示這次的commit做了怎麼樣的更新,並且會出現在 GitHub 上,方便之後做確認,或是讓其他共同工作的夥伴知道自己做了怎麼樣的更新。 #### **++新增一個遠端的 server++** 到前一步為止,我們的操作都是在自己的電腦上,接下來要連接到遠端的 Git。首先要設定一個端節的節點,例如: ``` git remote add origin git@github.com:cjm-jamie/my-new-projects.git ``` 這裡記得要選擇 **ssh** 的網址,可以到這裡複製: ![](https://i.imgur.com/YmCxtfE.png) #### **++把檔案推上遠端的 Git 伺服器++** ``` git branch -M main git push -u origin main ``` 如果在 push 的時候出現版本不同,無法 push 的問題,可以嘗試在 "-u" 後用 "-f",代表覆蓋掉之前所有的檔案,用新的檔案取代,這樣就不會出現版本不同而無法上傳的問題,但也**要確認目前 GitHub 上的檔案是可以被取代的才能這樣做,否則可能會被追殺==+**。請謹慎使用! 這裡要注意一下,因為原先舊版的Git預設branch是 "master",新版則是 "main",這部分可以在GitHub上看到,所以如果遇到類似下方的error: ``` error: src refspec main does not match any error: failed to push some refs to 'github.com:cjm-jamie/2023_ML.git' ``` 可以先確認自己在哪一個 branch 底下: ``` git branch ``` 如果發現不對,可以嘗試以下方法解決: ``` git branch -M main ``` 再 push 到 origin 一次 ``` git push -u origin main # for first time, next time can only enter "git push" ``` #### **++第一次 push 全部步驟 All Together++** ``` git init git add -A git commit -m 'Added my project' git remote add origin git@github.com:cjm-jamie/my-new-project.git git status git pull git push -u origin main ``` #### Official recommendation of first commit ``` echo "# EE6620_computational_photography" >> README.md git init git add README.md git commit -m "first commit" git branch -M main git remote add origin git@github.com:cjm-jamie/EE6620_computational_photography.git git push -u origin main ``` #### 刪除 repository 1. 刪掉 github 上的 repo 2. 刪掉 local 的 .git folder/ LICENCE file - 參考[網址](https://franksios.medium.com/github-%E5%88%AA%E9%99%A4github%E4%B8%8A%E7%9A%84%E5%B0%88%E6%A1%88-a3218b1beafe) ### **++後記++** >這次在push的時候因為名字從master改到main,一直push不上去,卡了好久,但是最後成功解決還是很有成就感!接下來要開始學期中的忙碌了,希望接下來還能持續生產筆記! >Keep going! :)) #### 參考網址 1. https://docs.github.com/en 2. https://www.digitalocean.com/community/tutorials/how-to-push-an-existing-project-to-github 3. https://www.baeldung.com/java-git-src-refspec-match 4. https://gitbook.tw/chapters/github/push-to-github <hr> <div style="text-align:right;"><h6>撰於 2023/3/20</h1></div>

    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