gitlab和github一塊兒使用

仍是在轉我筆記上的內容, 也算備份git

參考(https://segmentfault.com/a/1190000002994742)
能夠對比着看, 我記得參考裏面有個點沒有說詳細, 我把本身的流程記下來了,但願對你們有用github

上一份工做要用gitlab, 折騰了好長時間才能同時用githubgitlab, 下面是我使用的詳細流程, 注意若是比較在乎github的小綠點的話要把github設置爲globalsegmentfault

首先都已經註冊了gitlab和github的帳戶

生成祕鑰

ssh-keygen -t rsa -C "註冊的gitlab郵箱"

提示要輸入名稱, 無論, 一路回車, 也不要設置密碼ssh

ssh-keygen -t rsa -C "註冊的github郵箱"

此次名稱輸入id_rsa_github, 路徑保存在/home/ql/.ssh/下面gitlab

添加ssh key

~/.ssh路徑下分別有spa

  • id_rsa
  • id_rsa.pub
  • id_rsa_github
  • id_rsa.github.pub

分別讀取id_rsaid_rsa_githubcode

cat id_rsa.pub    # gitlab的祕鑰
cat id_rsa_github.pub    #github的祕鑰

把內容分別複製到gitlab和githubit

添加config

~/.ssh下添加config配置文件email

ql@ql:~/.ssh$ ls
config  id_rsa  id_rsa_github  id_rsa_github.pub  id_rsa.pub  known_hosts
ql@ql:~/.ssh$

config內容配置

# gitlab
Host gitlab

    HostName gitlab.com        
    IdentityFile ~/.ssh/id_rsa

# github
Host github
    HostName github.com
    IdentityFile ~/.ssh/id_rsa_github

設置倉庫

  • gitlab的工做倉庫是workspace, 進入目錄下
~/workspace$ git config --global user.name "用戶名"

~/workspace$ git config --global user.email "註冊郵箱"

~/workspace$
  • github的工做目錄是github, 若是要設置爲local的要先初始化, 能夠後面rm -rf .git刪掉
~/github$ git config --local user.name "github用戶名"
~/github$ 
~/github$ git config --local user.email "註冊郵箱"
~/github$

注意: 若是把github設置爲local的話, 提交代碼github上不會有小綠點, 我剛開始不知道, 可是能提交上去, 後天從新搞了一次才正常

相關文章
相關標籤/搜索