Try   HackMD

Git Tutorial

Start a git project

git init

初始化

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

git clone

複製下載
git clone <網址>

About git remote

git push & pull

上傳/下載 遠端

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

About git commit

git add

增加檔案到暫存區

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

git rm

從暫存區移除檔案

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

git log

顯示提交變更

git status

顯示變更檔案的狀態

git commit

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

git revert

移除 commit,在需要移除的 commit 按右鍵

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

About git branch

git switch

切換分支

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

git branch

建立分支

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

git merge

分支合併

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

merge 種類

  • merge (fast-forward merge)
    預設 merge 選項,會將兩分支的 commit 按時間戳記排序並整合成同分支
  • merge without fast-forwarding
    會保留兩分支的 commit ,並新增 merge 的 commit 在合成分支上

git tag

建立標籤

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

git for vscode

github ssh setting

  1. 輸入 ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

    成功後會顯示

    ​​​​Generating public/private rsa key pair.
    ​​​​Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
    ​​​​Enter passphrase (empty for no passphrase): [Type a passphrase]
    ​​​​Enter same passphrase again: [Type passphrase again]
    

    之後就是輸入兩次密碼

  2. 輸入 cat ~/.ssh/id_rsa.pub

  3. 複製整串印出來的東西

  4. 到 github/gitlab 網站

    • github
      1. settings->SSH and GPG kyes
      2. 按 New ssh key
      3. 在 key 貼上複製的東西
      4. add SSH key
    • gitlab
      1. Edit profile
      2. SSH keys
      3. 按 Add new key
      4. 在 key 貼上複製的東西
      5. Add key
  5. 測試
    輸入 ssh -T git@gitlab.com,應該會顯示

    ​​​​Hi <ACCOUNT_NAME>! You've successfully authenticated, but GitHub does not provide shell access.
    

github/gitlab auto login setting

  1. 開啟 git bash terminal

    1. 在 terminal 右手邊 加號右邊的向下箭頭
    2. git bash
  2. 輸入 eval "$(ssh-agent -s)"

  3. ssh-add ~/.ssh/id_rsa

設定預設帳號

  1. git config --global user.name "USER_NAME"
  2. git config --global user.email johndoe@example.com