Copy git repository to offline machine and pushing/pulling via memory-stick

To copy a complete Git repo, you just have to copy the folder .git; it contains everything. Git uses safe file names and ignores time stamps inside of the repo, so this data is safe from the usual file system quirks.

On the target machine, create a folder, copy the .git folder inside. Now git checkout <branch> will get you a working copy.

If you want to move patches back and forth instead of the whole repo, then git format-patch <branch> creates them. The command will create all patches necessary to update a remote repo (i.e. the output will contain everything that hasn't been pushed, yet). you can also give it commit IDs (= start with this commit) or ranges.

To apply them, use git am < 0001.... on the remote repo.

Related:

  • http://rypress.com/tutorials/git/patch-workflows

For copying your repo to the memory-stick, simply use git clone, and then use git pull to update it.

E.g., on your online computer, with the memory-stick mounted, do

cd <memory-stick-mount-point>
git clone <local-path-to-git-repo>

now the <local-path-to-git-repo> will be the origin remote for the repo on your usb-stick, so later you can simply use git push/pull (when mounted on the online machine) to sync your offline work.

The git repo on the memory stick is self-contained, so now you can work against that on any computer, and then sync as above when you mount it on your online machine.

Edit, re: not being allowed to mount the stick yourself:

If you can ask the admin to git clone the repo onto the memory stick it is fine. Otherwise, your admin can simply copy the entire project.git directory (if it's a bare repo) or project/.git (otherwise) to your memory stick, and you can work against that, the thing to watch out for is that the remotes, etc. will be those of the online machine.

Then, pulling is not a problem, but pushing may need a further work-around if you don't trust your sysadm to resolve your merge conflicts for you. If you have your own branch(es) then merging is not a problem. Otherwise to do merges "offline", you could have two offline copies of the repo, one that you work on, and one that is your "origin", and when you get back, ask the sysadm to git pull to the "origin" repo, and then, on an offline computer, do the merge between the two memory-stick repos, and then ask the sysadm to merge your origin repo into the online one.

This feels a bit brittle and open to race conditions, though, so I'd really try to create separate branches before "going offline".


The command git bundle is designed for this. For example, to clone the master branch of the repository offline,

cd my-repository
git bundle create offline-repos master

That will store the entire master branch in a file named offline-repos. Copy the file to another computer. On that computer, type

git clone -b master offline-repos new-repos

That will create the folder new-repos, checked out from offline-repos. The bundle file you cloned from will be treated as a remote repository. You can even create a bundle that store the changes since a ref, as in:

git bundle create offline-repos e45ad329..master

If you replace the bundle file offline-repos with a bundle containing new changes, you can git pull from it, as in:

cd new-repos
git pull