hakuei0115
    • 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
    # GitHub 建立 Repo & VS Code 提交/推送(Commit / Push)教學 > 目標:你會完成一個完整流程:**GitHub 建 repo → 本機用 VS Code 初始化/連結 → Commit → Push → 後續更新** > 適用:Windows / macOS / Linux(介面文字可能略不同,但流程一致) --- ## 0. 事前準備(必做一次) ### A. 安裝 Git - Windows:建議安裝 Git for Windows(安裝完會附 Git Bash) - macOS:可用 Homebrew 安裝或使用 Xcode Command Line Tools - Linux:用套件管理器安裝 安裝完確認: ```bash git --version ``` ### B. 設定 Git 使用者資訊 ```bash= git config --global user.name "你的名字" git config --global user.email "你的信箱" ``` ### C. 登入 GitHub - VS Code 右下角或 Command Palette(Ctrl+Shift+P / Cmd+Shift+P) - 搜尋:GitHub: Sign in - 依提示用瀏覽器登入 > 如果你用 HTTPS 推送,後續會走瀏覽器授權/Token;用 SSH 則要設定 SSH key(進階章節有)。 --- ## 1. 在 GitHub 建立 Repo(網頁操作) 1. 打開 GitHub → 左上角 + → New ![image](https://hackmd.io/_uploads/Hy8TtcoI-g.png) 2. 填寫: - Repository name:例如 my-project - Public / Private:選你要的 3. 初始化選項(建議): - Add a README file(新手建議勾) - Add .gitignore(可選,例如 Node / Python) - Choose a license(可選) 4. 按 Create repository ![image](https://hackmd.io/_uploads/rkDZ99oL-l.png) 建立完成後,記下 repo URL(通常長這樣): - HTTPS:https://github.com/<user>/<repo>.git - SSH:git@github.com:<user>/<repo>.git ![image](https://hackmd.io/_uploads/ByhQ95jI-e.png) --- ## 2. 方式一:你本機已經有專案 → 推到 GitHub ### A. 用 VS Code 打開你的專案資料夾 VS Code → File → Open Folder... → 選專案資料夾 ### B. 初始化 Git(如果你還沒 git init) VS Code 左側 Source Control(版本控制) 若看到「Initialize Repository」→ 按下去 或用終端機: ```bash git init ``` ### C. 加入檔案到暫存區(Stage) VS Code → Source Control: 在 Changes 區塊按 +(Stage All Changes 或單檔 Stage) 或終端機: ```bash git add . ``` ### D. 建立第一次提交(Commit) VS Code → Source Control 上方輸入訊息,例如: init: first commit 然後按 Commit(勾勾圖示) 或終端機: ```bash git commit -m "init: first commit" ``` ### E. 加入遠端 repo(Remote: origin) 回到 GitHub repo 頁面,複製 HTTPS/SSH URL。 終端機(建議最直覺): ```bash git remote add origin https://github.com/<user>/<repo>.git ``` 確認 remote 有沒有成功: ```bash git remote -v ``` ### F. 推送到 GitHub(Push) 第一次推送通常要設定 upstream(主分支可能是 main): ```bash git branch -M main git push -u origin main ``` > -u 會把本機 main 跟遠端 main 綁定,之後只要 git push 就好。 --- ## 3. 方式二:GitHub 已有 Repo → 你要下載到本機(Clone)(我常用的方法) ### A. 在 GitHub Repo 頁面按 Code → 複製 URL ![image](https://hackmd.io/_uploads/rygv35oLWl.png) ![image](https://hackmd.io/_uploads/BJHp3coIbx.png) ### B. 用 VS Code Clone 1. VS Code → Ctrl+Shift+P / Cmd+Shift+P 2. 輸入:Git: Clone 3. 貼上 URL ![image](https://hackmd.io/_uploads/BysMa5s8-x.png) 4. 選本機資料夾 → 開啟專案 或終端機: ```bash git clone https://github.com/<user>/<repo>.git cd <repo> code . ``` --- ## 4. 日常開發流程(最常用) 每次改完程式,基本流程就是: 1. 檔案變更 2. Stage(選要提交的檔) 3. Commit 4. Push VS Code 版: - Source Control ![image](https://hackmd.io/_uploads/HkBbRcj8We.png) - $+$ Stage ![image](https://hackmd.io/_uploads/SknXR9iU-l.png) - 輸入訊息 ![image](https://hackmd.io/_uploads/BJ34RqoI-l.png) - Commit(勾勾) - Push(上方同步/推送按鈕) ![image](https://hackmd.io/_uploads/B1a8A5iLbl.png) 終端機版: ```bash git add . git commit -m "feat: update something" git push ``` --- ## 5. 常見狀況與排除 ### A. 我不知道現在狀態? ```bash= git status ``` ### B. 看提交紀錄 ```bash git log --oneline --decorate --graph ``` ### C. Push 被拒絕:遠端有更新(non-fast-forward) 先把遠端拉下來再推: ```bash git pull --rebase git push ``` > --rebase 通常比 merge 更乾淨(提交線比較直)。 ### D. 我不小心把不該提交的檔加進來(例如 .env) 先把它加入 .gitignore 如果已經被 Git 追蹤過,需要取消追蹤: ```bash git rm --cached .env git commit -m "chore: ignore env" git push ``` --- ## 6. 分支(Branch)基本用法(建議至少會) ### A. 建新分支 ```bash git checkout -b feature/login ``` ### B. 推送分支到 GitHub ```bash git push -u origin feature/login ``` ### C. 切回主分支 ```bash git checkout main ``` --- ##7.(進階)HTTPS vs SSH 怎麼選? HTTPS(windows常用) - 優點:不太需要額外設定 - 缺點:有時要重新授權(看環境) SSH(mac/linux常用) - 但如果不是自己電腦建議不要走這個 - 優點:穩定、免反覆輸入密碼/授權 - 缺點:第一次要設 SSH Key SSH 快速流程(概念版): 1. 產生 key: ```bash ssh-keygen ``` 2. 把 ~/.ssh/id_ed25519.pub 內容貼到 GitHub → SSH keys 3. remote 用 git@github.com:... 形式 --- ## 8. Commit 訊息建議格式(好維護) 常用慣例(類似 Conventional Commits): - feat: 新功能 - fix: 修 bug - chore: 雜項(依賴、設定) - docs: 文件 - refactor: 重構(不改功能) - test: 測試 例: - feat: add login page - fix: handle null token - docs: update README --- ## 9. 你應該記住的最小指令集 ```bash git status git add . git commit -m "message" git pull --rebase git push ``` --- ## 10. 快速檢查清單 - [ ] GitHub 建 repo - [ ] 本機專案 git init(或 clone) - [ ] git add . - [ ] git commit -m "..." - [ ] git remote add origin <url>(若 clone 可略) - [ ] git push -u origin main - [ ] 後續:改完 → add → commit → push

    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