# Git Tutorial ## Start a git project ### git init 初始化  ### git clone 複製下載 `git clone <網址>` ## About git remote ### git push & pull 上傳/下載 遠端   ## About git commit ### git add 增加檔案到暫存區  ### git rm 從暫存區移除檔案  ### git log 顯示提交變更 ### git status 顯示變更檔案的狀態 ### git commit  ### git revert 移除 commit,在需要移除的 commit 按右鍵  ## About git branch ## git switch 切換分支  ## git branch 建立分支  ## git merge 分支合併  ### merge 種類 * merge (fast-forward merge) 預設 merge 選項,會將兩分支的 commit 按時間戳記排序並整合成同分支 * merge without fast-forwarding 會保留兩分支的 commit ,並新增 merge 的 commit 在合成分支上 ## git tag 建立標籤  # 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`
×
Sign in
Email
Password
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