【转】把Git Repository建到U盘上去
把Git Repository建到U盘上去
转 把Git Repository建到U盘上去
Git很火。原因有三:
- 它是大神Linus Torvalds的作品,天然地具备神二代的气质和品质;
- 促进了生产力的发展,Git的分布式版本控制理念,并非首创,但非常适合开源社区的协作方式(不存在master-slave的关系)
- 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盘上能满足多种应用场景,特别是:
- 注重私密性(GitHub上普通账号不能创建私有repository)
- 网速很慢,甚至断网的时候需要同步
但不适合需要强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"
step 1.4
把所有"untracked files"加入索引
step 1.5
提交到repository
$ git commit -m "initialized."
2, 搞到U盘上去
step 2.1
插上U盘,查看U盘挂载路径
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
查看提交历史
发现两台电脑上提交的记录都在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盘上去的更多相关文章
- 把Git Repository建到U盘上去(转)
把Git Repository建到U盘上去 转 把Git Repository建到U盘上去 Git很火.原因有三: 它是大神Linus Torvalds的作品,天然地具备神二代的气质和品质: 促进了生 ...
- 把Git Repository建到U盘上去
Git很火.原因有三: 它是大神Linus Torvalds的作品,天然地具备神二代的气质和品质: 促进了生产力的发展,Git的分布式版本控制理念,并非首创,但非常适合开源社区的协作方式(不存在mas ...
- git: fatal: Not a git repository (or any of the parent directories): .git
在看书 FlaskWeb开发:基于Python的Web应用开发实战 时,下载完源码后 git clone https://github.com/miguelgrinberg/flasky.git 试着 ...
- git 解决fatal: Not a git repository
我用git add file添加文件时出现这样错误: fatal: Not a git repository (or any of the parent directories): .git 提示说没 ...
- 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 ( ...
- 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 ...
- 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添加文件时出现这样错误 ...
- 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 ...
- 执行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 ...
随机推荐
- 简单的RNN和BP多层网络之间的区别
先来个简单的多层网络 RNN的原理和出现的原因,解决什么场景的什么问题 关于RNN出现的原因,RNN详细的原理,已经有很多博文讲解的非常棒了. 如下: http://ai.51cto.com/art/ ...
- uc浏览器app点评
uc浏览器app我经常用,是我接触的第一款手机浏览器,感觉还不错的,uc浏览器新闻更新速度有点慢,有时候还闪退,以前在搜索栏粘贴文字后,如果想改后面的文字,根本就不行,用uc浏览器下东西速度比较慢,现 ...
- 读书笔记(chapter5)
系统调用 5.1与内核通信 1.系统调用在用户空间进程和硬件设备之间添加一个中间层.作用有三个:它为用户空间提供了一种硬件的抽象接口:系统调用保证了系统的稳定和安全:系统调用是用户空间访问内核的唯一手 ...
- 小组冲刺第十四天站立会议(Beta版发布)
注: “助成”招聘网站链接:http://58.87.74.131:8080/zhucheng 欢迎大家进行评测. 一.任务看板: 二.燃尽图: 三.任务总结: 根据前期收集的用户反馈,再次对网站进行 ...
- Android TextView中图文混排设置行间距导致高度不一致问题解决
最近项目中需要实现一个评论带表情的功能,刚开始一切顺利,非常easy,突然有一天发现文字跟表情混排的时候,TextView中图文高度不一致,excuse...什么鬼,之前明明测试过图文混排,不存在这个 ...
- Visual Studio(VS)C++单元测试
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Visual Studio(VS)C++单元测试 本文地址:http://techie ...
- Linux命令(十三) 建立目录 mkdir 删除目录 rmdir
一.建立目录 mkdir 命令简介 mkdir 命令用于创建指定的目录.创建目录时当前用户对需要操作的目录有读取权限.如果目录已经存在,会提示报错并推出. mkdir 可以创建多级目录. 常用参数说明 ...
- OI回忆录第一章 逐梦之始
2013年春,初中零年级.GXZ来到吉大高中机房,参加一位老师曾在班级宣传的"计算机培训".同行的有这位老师,以及近80名同学.和同学们一样,GXZ也是为了在机房玩游戏而参加所谓的 ...
- 【刷题】BZOJ 4916 神犇和蒟蒻
Description 很久很久以前,有一只神犇叫yzy; 很久很久之后,有一只蒟蒻叫lty; Input 请你读入一个整数N;1<=N<=1E9,A.B模1E9+7; Output 请你 ...
- 【转】PCB中3D相关功能详解
如果PCB Layout工程师能够在设计过程中,使用设计工具直观地看到自己设计板子的实际情况,将能够有效的帮助他们的工作.尤其现在PCB板的设计越来越复杂,密度越来越高,如果能够洞察多层板内部则可以帮 ...