使用GIT BASH管理多個遠程代碼庫

使用GIT BASH管理多個遠程代碼庫技術

maybe yes 發表於2015-01-15 13:11php

原文連接 : http://blog.lmlphp.com/archives/62  來自 : LMLPHP後院git

個人另外一篇文章《GITHUB之GIT BASH使用教程》, 最近一段時間,百度等搜索引擎也帶來了一些流量,看到有不少網友瀏覽,也有網友來過屢次。這篇文章再作一些補充,關於如何使用 GIT 推送代碼到多個遠程代碼庫。使用場景:好比咱們的項目同時放到了 GITHUB 和 GITOSC 中,這個時候本地只有一份項目代碼,當本地開發時作了更新,要保持遠程兩個遠程版本庫的一致性,就必須將代碼同時推送到兩個遠程服務器。github

這裏將不使用 GITHUB 自帶的 GIT 客戶端,GITHUB for windows 客戶端作了定製化,對於推送到其餘服務端不太方便。數據庫

在 GIT 客戶端中,使用 eval `ssh-agent` (注意是數據庫字段符號,也就是鍵盤數字 1 左邊的那個按鍵)命令進入 SSH 模式,打開祕鑰管理器,而後使用 ssh-add 命令添加私鑰。不少不太熟悉的人每每由於沒有執行 ssh-agent 而致使不能使用 ssh 命令鏈接到服務器。windows

國內的 GIT 託管服務 GITOSC 不能使用 SSH 協議來進行推送代碼功能,只能用來拉取項目更新,官方建議使用 https 協議來進行代碼的推送,這樣有個不方便,就是每次都須要輸入用戶名和密碼。網上也有教程使 https 協議下可以記住密碼的方法,可是感受太過於麻煩,本人更習慣於 SSH 帶來的方便。我第一次將 LMLPHP 代碼託管在 GITOSC 的時候,因爲習慣了 GITHUB 的 SSH 操做,對於 https 協議推送反而不知道怎麼使用。從下面的操做日誌中,能夠看到 .git/config 文件中的內容,能夠經過修改該配置文件添加遠程庫,或者使用 」git remote add origin_xxx address「 的方式來增長遠程庫。下面的操做例子中,遠程庫 origin_gitosc 是使用 https 協議來進行推送的,每次推送更新都須要輸入用戶名和密碼;遠程庫 origin 是使用 SSH 協議來進行代碼推送的,須要自行添加祕鑰文件,祕鑰文件在生成的時候能夠設置密碼,有了密碼後,每次執行 」ssh-add「 命令時,須要輸入密碼才能夠被添加,也算是一種安全保護措施。安全

Welcome to Git (version 1.9.4-preview20140929)


Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.

May@MAY-PC ~
$ cd Documents/

May@MAY-PC ~/Documents
$ cd GitHub/LMLPHP/

May@MAY-PC ~/Documents/GitHub/LMLPHP (develop)
$ git status
On branch develop
Your branch is up-to-date with 'origin/develop'.

nothing to commit, working directory clean

May@MAY-PC ~/Documents/GitHub/LMLPHP (develop)
$ git branch -av
* develop                       e6e8db4 modify default_theme_name constant name
  master                        e6e8db4 modify default_theme_name constant name
  remotes/origin/HEAD           -> origin/master
  remotes/origin/develop        e6e8db4 modify default_theme_name constant name
  remotes/origin/master         e6e8db4 modify default_theme_name constant name
  remotes/origin_gitosc/develop e6e8db4 modify default_theme_name constant name
  remotes/origin_gitosc/master  e6e8db4 modify default_theme_name constant name

May@MAY-PC ~/Documents/GitHub/LMLPHP (develop)
$ git pull origin develop
From github.com:leiminglin/LMLPHP
 * branch            develop    -> FETCH_HEAD
Already up-to-date.

May@MAY-PC ~/Documents/GitHub/LMLPHP (develop)
$ ls
LICENSE  README.md  lib  lml.min.php  lml.php  lmlphp_logo_200.png

May@MAY-PC ~/Documents/GitHub/LMLPHP (develop)
$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
        hideDotFiles = dotGitOnly
[remote "origin"]
        url = git@github.com:leiminglin/LMLPHP.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "develop"]
        remote = origin
        merge = refs/heads/develop
[remote "origin_gitosc"]
        url = https://git.oschina.net/leiminglin/LMLPHP.git
        fetch = +refs/heads/*:refs/remotes/origin_gitosc/*

May@MAY-PC ~/Documents/GitHub/LMLPHP (develop)
$ eval `ssh-agent`
Agent pid 13436

May@MAY-PC ~/Documents/GitHub/LMLPHP (develop)
$ ssh-add ./../../../.ssh/github_rsa
Identity added: ./../../../.ssh/github_rsa (./../../../.ssh/github_rsa)

May@MAY-PC ~/Documents/GitHub/LMLPHP (develop)
$

PS :看來本博客迫切須要一個相關文章功能,除了後臺能夠自定義,程序自動尋找更好。服務器

閱(63)評(0)查看評論ssh

相關文章
相關標籤/搜索