git在不用github这种远程仓库时,如何实现异地同步呢?html
下班前提交代码,回家后同步代码继续开发并提交,次日来公司继续……git
这里作个实验:用网盘的目录同步功能,咱们打造一个"伪远程仓库"。github
以金山快盘为例:shell
步骤1. 在本地找个目录做为"远程仓库",假设咱们将 e:\kuaipan\phalcon 这个做为远程仓库,那么就将这个目录拖进快盘(U盘)里,而后再快盘客户端里右键该目录,开启同步。spa
步骤2. 建立裸版本库,根据git的规则,只有裸版本库才能接受git push/pull请求。因此咱们这样操做(在cygwin虚拟环境下):code
<!-- lang: shell --> cd e:/kuaipan/phalcon git init --bare
步骤3. 建立本地的版本库,假设在 e:/workspace/phalcon_local 建立 <!-- lang: shell --> cd e:/workspace git clone e:/kuaipan/phalcon phalcon_localhtm
步骤4. 开发,并提交 <!-- lang: shell --> cd e:/workspace/phalcon_local touch index.html git add . && git commit -m "add index.html" git push e:/kuaipan/phalcon master 咱们在本地工做区建立了一个index.html,并提交到本地库(git commit),以后咱们将本地版本库推送到“远程仓库中”(git push)。ip
步骤5. 假设到家了,咱们打开快盘,将快盘中的目录phalcon同步到本地,至关于把公司的远程库拷贝了一份,假设同步到了 d:/kuaipan/phalcon 而后到工做区开发
<!-- lang: shell -->同步
cd d:/workspace git clone d:/kuaipan/phalcon phalcon_local cd phalcon_local ...... git add . && git commit -m "---over---" git push d:/kuaipan/phalcon
咱们在家里完成了一些工做,最后一样push到了远程仓库,远程仓库发生了一些变化,会自动同步到快盘里。
步骤6. 次日到公司,重复步骤5相似的操做。