mirror of
https://github.com/beyondx/Notes.git
synced 2026-02-10 05:46:18 +08:00
58 lines
3.1 KiB
Plaintext
58 lines
3.1 KiB
Plaintext
Content-Type: text/x-zim-wiki
|
||
Wiki-Format: zim 0.4
|
||
Creation-Date: 2011-05-16T21:57:29+08:00
|
||
|
||
====== Git sync via USB ======
|
||
Created Monday 16 May 2011
|
||
http://blog.ekynoxe.com/2010/11/17/git-sync-via-usb/
|
||
|
||
Right, suppose you need to sneakernet some git repository changes, Maybe your network is down and you want to send changes to co-workers or another machine from which you have a full network access. Maybe you’re somewhere without access to the a network and/or the correct ports/protocols for security reasons. Maybe all network connections are down and you really need to transfer your changes to someone else. How do you go about that?
|
||
|
||
Of course, there is the **git-bundle** solution, but I feel it is probably more suited to large projects where you only need to sync changes about small parts of the code base, rather than the whole repo, and it involves creation of bundle files which I was not too happy about doing.
|
||
|
||
I therefore went instead on the route of **creating a normal repo on my USB stick and using it as the transport mean**. This involves **creating a bare repo on the usb stick and adding the correct remote branches on machines either side of the transfer.**
|
||
|
||
I’m working on a mac, so you’ll have to adapt the paths to your own situation. My USB stick is mounted on
|
||
|
||
/Volumes/USB_STICK/
|
||
|
||
===== On USB stick, from machine A =====
|
||
|
||
All you need to do is set up bare repo (and that’s all!)
|
||
**machineA$ cd /Volumes/USB_STICK/desired_repo_path/**
|
||
**USB_STICK$ git init --bare**
|
||
|
||
===== On machine A (holding the initial code) =====
|
||
|
||
First, set up your git repository normally if it’s **not already** done:
|
||
**machineA$ cd /my/files/path/**
|
||
**machineA$ git init**
|
||
**machineA$ git add .**
|
||
**machineA$ git commit -m "initial commit"**
|
||
|
||
Then simply __add a remote branch pointing at the usb stick repo__
|
||
**machineA$ git remote add **__stick__** /Volumes/USB_STICK_NAME/desired_repo_path/**
|
||
**machineA$ git push -u stick master**
|
||
|
||
You have now pushed your complete repository (the master branch to be more precise) on the usb stick. All you need to do is to pull it from your second machine!
|
||
|
||
===== On machine B (Where you want to transfer the code to) =====
|
||
|
||
Set up a new repository to receive the code, add a remote branch from the stick and pull the changes as you would normally do
|
||
**machineB$ cd /path/where/IWant/My/Files/**
|
||
**machineB$ git init**
|
||
**machineB$ git remote add stick /Volumes/USB_STICK_NAME/desired_repo_path/**
|
||
**machineB$ git **__pull -u__** stick master**
|
||
|
||
You now have transferred your code from MAchine A to Machine B, and you can work normally on this machine, committing as you normally would. Then, to transfer the changes back to machine A. Nothing more simple:
|
||
**On machine B**
|
||
__machineB$ git push stick__
|
||
**On machine A**
|
||
__machineA$ git pull stick__
|
||
|
||
From there, if you have set up a remote tracking branch on a network server that co-workers pull from of from which you checkout code for deployment, you can now do a simple
|
||
__machineA$ git push__
|
||
|
||
**PS:**上面一条语句将本地仓库中的代码push到所有的远程服务器上(包括USB设备)
|
||
And you’re good!
|