【转】把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 ...
随机推荐
- 【LeetCode】数组--合并区间(56)
写在前面 老粉丝可能知道现阶段的LeetCode刷题将按照某一个特定的专题进行,之前的[贪心算法]已经结束,虽然只有三个题却包含了简单,中等,困难这三个维度,今天介绍的是第二个专题[数组] 数组( ...
- Ubuntu 18.04下Couldn't connect to Docker daemon at http+docker://localunixsocket解决办法
一台服务器系统为:Ubuntu 18.04 LTS,上面建了git裸仓库,用于开发吧代码push到这里.同时WEB测试环境通过docker也部署在这台.通过git钩子post-receive,当有新代 ...
- PAT甲题题解-1059. Prime Factors (25)-素数筛选法
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为i ...
- Alpha阶段个人贡献分
根据任务完成情况与之前的评分标准,我们给组员分数如下: 团队成员 最终得分 程刚 49 李睿琦 50 刘丽萍 52 刘宇帆 53 王力民 54 杨昊岚 41 左少辉 51 转会人员: 杨昊岚转到Our ...
- linux内核分析第一周学习笔记
linux内核分析第一周学习笔记 标签(空格分隔): 20135328陈都 陈都 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.co ...
- 小组成员的github地址
袁颖https://github.com/joanyy/test 魏晓 https://github.com/weixiaohaobaobao/test 张晓磊 https://github.com/ ...
- 使用phantomjs进行无界面UI自动化测试
PhantomJS(http://phantomjs.org/) 是一个基于WebKit的服务器端JavaScript API.它全面支持web而不需浏览器支持,其快速.原生支持各种Web标准:DOM ...
- CentOS 简单学习 firewalld的使用
1. centos7 开始 使用firewalld 代替了 iptables 命令工具为 firewall-cmd 帮助信息非常长,简单放到文末 2. 简单使用 首先开启 httpd 一般都自带安装了 ...
- LOJ 530 最小倍数(数论)
题意 有\(T\)组数据. 给定\(p\),求最小的正整数\(n\),使得\(n!\%p=0\). 由于\(p\)很大,输入将给出\(m\)和\(e_1,e_2...e_m\),表示\(p=\prod ...
- BZOJ1815 SHOI2006有色图(Polya定理)
置换数量是阶乘级别的,但容易发现本质不同的点的置换数量仅仅是n的整数拆分个数,OEIS(或者写个dp或者暴力)一下会发现不是很大,当n=53时约在3e5左右. 于是暴力枚举点的置换,并且发现根据点的置 ...