18

Say my co-hacker and I find ourselves on a desert island. Normally we push and pull to github to sync with each other. How would you recommend we do so when we have no connection to the outside world?

(User @bee and I actually have that problem as I type this, though obviously not as I send this. In our case we both have Mac laptops -- OSX Snow Leopard -- but I think it would be better to treat this question generically.)

Community
  • 1
  • 1
dreeves
  • 26,430
  • 45
  • 154
  • 229

5 Answers5

19

Take a SD-Card, or an USB-stick or something. Create a bare repository there. Then one push to that repo, unmount the card/stick, give it to the other, that one pull from it.

cd /path/to/usbstick
mkdir repo
cd repo
git init --bare
cd /path/to/local/repo
git remote add usb /path/to/usbstick/repo
git push usb --all

One the other machine

cd /pat/to/local/repo
git remote add usb /path/to/usbstick/repo
git fetch usb --all
Community
  • 1
  • 1
KingCrunch
  • 128,817
  • 21
  • 151
  • 173
17

The simplest solution is probably to just set up an ad-hoc wireless and SSH to eachother's laptops. You can set up your remote with

$ git remote add cohacker myuser@cohackers-laptop:/path/to/repo.git

Now you can push/pull to your heart's content:

$ git pull cohacker master
 ... hack away ...
$ git push cohacker master
hammar
  • 138,522
  • 17
  • 304
  • 385
  • I'm a newbie programmer. Would you recommend a good tutorial on how to set-up an ad-hoc wireless and SSH to connect two Macs. – Sami Dec 08 '14 at 18:37
10

One solution compatible with your scenario would be to share through an USB stick one file through git bundle

That allows you to:

  • consider that one file (the 'bundle') as an upstream repo to which each user can update said bundle, and from which they can fetch new commits.
  • avoid trying to synchronize a large collection of files/meta data within a bare repo structure.
  • don't rely on any network/server process whatsoever.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Which desert islands have somewhere that you can get a USB stick? :) – William Pursell May 10 '11 at 16:11
  • 2
    @William: I was alluding more to the "no internet" part than to the "desert island" part of the question: `git bundle` is the way to transfer repo with no connexion whatsoever, that was my point. – VonC May 10 '11 at 16:53
  • 1
    This is the best answer for my use case, where I have two servers that can not communicate directly with one another, and for which it is not convenient to use a bare repository (which may be gigabytes in size) to communicate changes. This lets me catch one server's repo up to the other by only considering the differences between their most recent common ancestor refspec, rather than the bare repo solution which requires the entire working history be transmitted. This is clearly the best solution, as it is OS agnostic and doesn't depend on any network or transmitting the entire history. – Taywee Sep 02 '16 at 22:59
2

Running a git server locally should work if you're on the same network. One would push to his own machine, the other to the other machine (based on local IP).

Roy
  • 117
  • 5
2

For starters - get this book - http://book.git-scm.com/

Indispensable

Second, there is a section on page 40 titled Distributed Workflows

That should cover what you need, just use ssh as your comms protocol (assuming you're familiar with ssh from command line)

Dave G
  • 9,639
  • 36
  • 41