Git很火。原因有三:

  1. 它是大神Linus Torvalds的作品,天然地具备神二代的气质和品质;
  2. 促进了生产力的发展,Git的分布式版本控制理念,并非首创,但非常适合开源社区的协作方式(不存在master-slave的关系)
  3. GitHub

GitHub很好,号称代码界的facebook.

facebook,twitter,Microsoft,vmware,redhat,LinkedIn,Yahoo等公司都在GitHub上有建立数目不等的repositories。一些知名开源项目,例如jQuery, Ruby on Rails,node.js都把src code寄存于GitHub上。GitHub太成功了,以至于使很多人产生误解,以为git就是GitHub,使用git就必须连接GitHub。事实上,GitHub只是一个提供git repository hosting服务的网站。

本文试图讲解如何在U盘上创建git repository(使U盘成为你的私有代码云);以及如何在不同客户端进行同步作业。把git repository建在USB盘上能满足多种应用场景,特别是:

  1. 注重私密性(GitHub上普通账号不能创建私有repository)
  2. 网速很慢,甚至断网的时候需要同步

但不适合需要强collaborate的项目。

前提条件

先把git给装好了…然后…我们有了两台git ready的电脑,和一个U盘。

开始,1,初始化本地repository

假设有一个存在的项目,需要由git接管版本控制,那么来到这个%projct_home%目录(例如我的git_sandbox)下

step 1.1

初始化

$ git init git_sandbox

step 1.2

创建.gitignore文件(在%project_home%下,只对这个project有效),排除路径下不需用被提交到repository中的文件(例如.svn,.class, Thumbs.db…)

step 1.3

查看当前文件状态,可以看到有一堆”untracked files”

$ git status

step 1.4

把所有”untracked files”加入索引

$ git add .

step 1.5

提交到repository

$ git commit -m "initialized."

2, 搞到U盘上去

step 2.1

插上U盘,查看U盘挂载路径

$ mount

我的路径是”/Volumes/KINGSTON”

step 2.2

在U盘上创建一个repository,

$ mkdir /Volumes/KINGSTON/workspace/usbGitSpace/gitusb_sandbox

$ cd /Volumes/KINGSTON/workspace/usbGitSpace/gitusb_sandbox

$ git init --bare

使用–bare选项创建的repository被称作bare repository,它不会包含working目录(只包含.git目录下的内容),所以不适合在上面改code。bare repository主要的作用就是被push和pull。根据GitFaq的说法:

A quick rule of thumb is to never push into a repository that has a work tree attached to it, until you know what you are doing.

step 2.3

回到本地%project_home%,把初始化后的usb repository添加为remote repository

$ git remote add usb /Volumes/KINGSTON/workspace/usbGitSpace/gitusb_sandbox

将本地的repository push到usb上

$ git push usb master

3, 同步到另一台电脑

step 3.1

在另一台电脑上先创建一个本地repository

$ cd ~/my_gitspace/sandbox_win

$ git init

step 3.2

把U盘插到这个电脑上,查看当前挂载的路径,添加U盘作为当前repository的remote repository

$ git remote add usb /cygdrive/f/workspace/usbGitSpace/gitusb_sandbox

step 3.3

把U盘上的内容拉下来

$ git pull usb master

好了,代码同步到另一台机器上了

4, 测试一下

step 4.1

改动一下文件,比如README.txt

step 4.2

$ git add README.txt

$ git commit -m "update from another laptop"

$ git push usb master

step 4.3

插回原来的laptop

$ git pull usb master

step 4.4

查看提交历史

$ git log

发现两台电脑上提交的记录都在log里面

好了,成功。现在U盘成为了你的GitHub,你和你的代码之间,再没有阻隔。

当然,最后,需要定期给U盘做一个备份。技术发展到今天,数据安全靠天吃饭的日子已经一去不复返了,没有什么U盘,硬盘是靠得住的。

原文链接: http://wuminqi.com/blog/2012/01/08/%E6%8A%8Agit-repository%E5%BB%BA%E5%88%B0u%E7%9B%98%E4%B8%8A%E5%8E%BB/

把Git Repository建到U盘上去的更多相关文章

  1. 把Git Repository建到U盘上去(转)

    把Git Repository建到U盘上去 转 把Git Repository建到U盘上去 Git很火.原因有三: 它是大神Linus Torvalds的作品,天然地具备神二代的气质和品质: 促进了生 ...

  2. 【转】把Git Repository建到U盘上去

    CHENYILONG Blog 把Git Repository建到U盘上去 转 把Git Repository建到U盘上去 Git很火.原因有三: 它是大神Linus Torvalds的作品,天然地具 ...

  3. git: fatal: Not a git repository (or any of the parent directories): .git

    在看书 FlaskWeb开发:基于Python的Web应用开发实战 时,下载完源码后 git clone https://github.com/miguelgrinberg/flasky.git 试着 ...

  4. git 解决fatal: Not a git repository

    我用git add file添加文件时出现这样错误: fatal: Not a git repository (or any of the parent directories): .git 提示说没 ...

  5. fatal: Not a git repository (or any of the parent directories): .git

    $ git remote add origin https://github.com/heyuanchao/YouxibiClient.gitfatal: Not a git repository ( ...

  6. Git CMD - init: Create an empty Git repository or reinitialize an existing one

    命令格式 git init [-q | --quiet] [--bare] [--template=<template_directory>] [--separate-git-dir &l ...

  7. git错误:fatal: Not a git repository (or any of the parent directories): .git

    git错误:fatal: Not a git repository (or any of the parent directories): .git 我用git add file添加文件时出现这样错误 ...

  8. git 使用过程中遇到的问题does not appear to be a git repository Could not read from remote respository

    想把本地的git库上传到github上.github已经新建了一个public仓库,利用网站的命令 git Bash报错:does not appear to be a git repository  ...

  9. 执行git命令时出现fatal: 'origin' does not appear to be a git repository错误

    在执行git pull origin master时出现: fatal: 'origin' does not appear to be a git repository fatal: Could no ...

随机推荐

  1. Apache Solr Velocity模板远程代码执行复现

    0x01漏洞描述 2019年10月31日,国外安全研究员s00py在Github公开了一个Apache Solr Velocity模板注入远程命令执行的poc. 经过研究,发现该0day漏洞真实有效并 ...

  2. CSPS模拟 81

    Z哥的题,真是见题如见人啊.. T1 实际状态数没有那么多,不要被数字吓倒就是了. 另外为什么吧轮廓线给忘了啊 T3 觉得自己是正解但是被hack了? 考试的时候想到了复杂度对的的解法,但是 spfa ...

  3. 深入理解C#第三版部分内容

     最近,粗略的读了<深入理解C#(第三版)>这本技术书,书中介绍了C#不同版本之间的不同以及新的功能. 现在将部分摘录的内容贴在下面,以备查阅. C#语言特性: 1.C#2.0 C#2的主 ...

  4. FHQ treap学习(复习)笔记

    .....好吧....最后一篇学习笔记的flag它倒了..... 好吧,这篇笔记也鸽了好久好久了... 比赛前刷模板,才想着还是补个坑吧... FHQ,这个神仙(范浩强大佬),发明了这个神仙的数据结构 ...

  5. 1005 csp-s 60 凉凉

    T1 嘟嘟噜 上来一看数据范围1e9就蒙蔽,然后不知所措的打了一个 $ O(n)$的无脑算法,由于本人真的脑小,导致O(n)的柿子推了好长时间,导致心态崩了,然后........ 今天能明白了log的 ...

  6. vue.config.js常用配置

    使用vue-cli3.0搭建项目比之前更简洁,没有了build和config文件夹. vue-cli3的一些服务配置都迁移到CLI Service里面了,对于一些基础配置和一些扩展配置需要在根目录新建 ...

  7. 【algo&ds】2.线性表

    1.线性表 线性表(英语:Linear List)是由n(n≥0)个数据元素(结点)a[0],a[1],a[2]-,a[n-1]组成的有限序列. 其中: 数据元素的个数n定义为表的长度 = " ...

  8. 【持续更新】【pat】pat刷题技巧记录

    修改code completion快捷键位CTRL+ENTER,帮助提示函数名称 修改命令行提示符的属性,开启快速编辑模式,方便调试 添加c++11语言标准支持 开启代码调试功能 对输入的字符串进行切 ...

  9. PHP 中四大经典排序算法

    1.冒泡排序 在要排序的一组数中,对当前还未排好的序列,从前往后对相邻的两个数依次进行比较和调整,让较大的数往下沉,较小的往上冒.即,每当两相邻的数比较后发现它们的排序与排序要求相反时,就将它们互换. ...

  10. nyoj 255-C小加 之 随机数 (map)

    255-C小加 之 随机数 内存限制:64MB 时间限制:3000ms 特判: No 通过数:15 提交数:18 难度:1 题目描述: ACM队的“C小加”同学想在学校中请一些同学一起做一项问卷调查, ...