設定 Git

分享 Git 設定

-3 min read

將個人的 ssh-key 加好至 GitLab

  1. 如果有 gen 過金鑰可跳過此步驟
ssh-keygen
  1. 貼上 ssh-key
cat ~/.ssh/id_rsa.pub | pbcopy
打開 [User Settings > SSH Keys]
 key 到右側輸入框內
Done
  1. SSH Key 的放置位置
  • ~/.ssh/ 底下
  1. 查看 SSH Key 的對應連結位置
code ~/.ssh/config
  1. SSH config 解說 (多組 key 時會用到)

code ~/.ssh/config

Host foo                        # gitlab.com 的別名, 之後可以用 git@foo 來取代 git@gitlab.com
HostName gitlab.com             # 指定要變換的 Repo domain
User git
IdentityFile ~/.ssh/id_rsa_foo  # 可以在 keygen 的時候指定名稱
IdentitiesOnly yes

批次重置 author

git-reset-author.sh

#!/bin/sh

$ git filter-branch -f --env-filter "
    GIT_AUTHOR_NAME='<Your Name>'
    GIT_AUTHOR_EMAIL='<Your Email>'
    GIT_COMMITTER_NAME='<Your Name>'
    GIT_COMMITTER_EMAIL='<Your Email>'
  " HEAD

ignore 本地某個檔案

git update-index --skip-worktree <file>