# github 踩雷紀錄 https to ssh 想說來練習下git吧 怎麼用個github一堆問題 後來想到 噢對,今年七月全面使用ssh key了 https禁用 所以我一開始抄的url就不能用了 但指示不清不楚的阿... 只有我在git push時會說git name錯誤 ![](https://i.imgur.com/8DdEZBp.png) 參考過程: 先在網站上開一個new reposity 複製上面提示的網址url 到git bash 指定到哪個資料夾 cd `git clone https://github.com/myaccount/HelloREADME.git` 後來push失敗 而且會跳出輸入視窗要我輸入帳號密碼 但不管輸入幾次都是錯的 想到喔對要改用SSH 所以照著指示去generate SSH key `ssh-keygen -t ed25519 -C "myaccount@gmail.com"` //用ed25519加密的意思 到github網站上setting處把pubkey內容貼上去 照著教學走~ 重點來了 有個東西叫做ssh-agent 要先打開 我後來用git bash這程式直接用 ``` $ eval "$(ssh-agent -s)" Agent pid 2031 ``` 將ssh key加入agent ``` $ ssh-add ~/.ssh/id_ed25519 Identity added: /c/Users/mat/.ssh/id_ed25519 (myaccount@gmail.com) ``` 忘記開ssh-agent的話會出現 ``` $ ssh-add ~/.ssh/id_ed25519 Could not open a connection to your authentication agent. ``` 接著應該可以直接git push了吧?! ``` $ git push fatal: The upstream branch of your current branch does not match the name of your current branch. To push to the upstream branch on the remote, use git push origin HEAD:master To push to the branch of the same name on the remote, use git push origin HEAD To choose either option permanently, see push.default in 'git help config'. ``` 沒有...這什麼指示? 後來查原來https跟ssh git name不一樣 一個是:,一個是/ 所以阿~不能混用阿(遠目 後來將remote改掉就可以了 `$ git remote set-url origin git@github.com:git@github.com:myaccount/myaccount.git` reference: 1. If it is asking you for a username and password, your origin remote is pointing at the HTTPS URL rather than the SSH URL.https://stackoverflow.com/questions/14762034/push-to-github-without-a-password-using-ssh-key 2. 官方的指引:https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh 3. 複製ssh-key金鑰到github網站上:https://blog.jaycetyle.com/2018/02/github-ssh/ 4. 只有說全面改用ssh-key但沒講很清楚怎麼做的官方文件:https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ 5. 看了這篇才知道名字有不一樣的關鍵錯誤:https://ithelp.ithome.com.tw/articles/10230636