The various cloud sync services provide a good way to backup or remote a Git repository for ‘single developer’ situations. The main advantages are that the cost is minimal and no ‘server’ is required. In this post we use something quite different, the new BitTorrent Sync (BTSync) system.
1. Single developer on multiple devices, PC, laptop, mobile. Also see Single Developer Git Workflow, .
2. Easy, fast, and lightweight code sharing setup. See also Sneakernet with Git
3. Ad Hoc Version Control: How to do Ad Hoc Version Control, Ad Hoc Version Control With Git
BTSync is a serverless folder syncing system. Instead of using a remote server storage system, it creates a fast private peer-to-peer file sync system using a P2P protocol. Note it is not necessarily a replacement for a server, backup system, or even other services such as DropBox, more like a welcome addition that covers some limits that others may have, such as file size limitations, speed, and privacy.
Using this type of service is very easy. I took the easy way out and “forked” a very well written blog post by Sergei Shvetsov that did the same thing, only using DropBox. Using Git with Dropbox. In this post, however, I use BTSync and I am running on Windows (most blogs show examples on *nix). Of course, experienced Git users may approach this very differently. The following uses a console shell UI.
1. Create a local repo
2. Create a “bare” repo that lives in the Synced folders
3. Add the bare repo as the origin of the local repo.
Now on another system, the synced folder, which contains the bare repo is available as if it was created locally. During development or other uses, since we are using the working repo and only occasionally the ‘bare’ or origin repo in the synced folder, the synced folder is not constantly transferring data over the network to any other synced locations (there can be many).
This approach is diagrammed below. (On mobile device this ASCII diagram using <PRE> tag looks horrible.) Two systems with the two Git repos:
+-----------------+ +----------------+ | Local | | Local | | Repo | | Repo | +-----------------+ +----------------+ ^ + + ^ | | | | | | push/pull | | push/pull | | | | | | + | + v v + +-----------------+ BT Sync +----------------+ | Bare | <-----------------+ | Bare | | repo | +------------------>| repo | +-----------------+ +----------------+
Of course whenever possible direct access to remote repos from a clone is preferred, or via a server. For private use and 5 users, Bitbucket offers free code repositories.
Below is a walkthrough of this process using a Windows cmd shell.
Create a local repository
C:\temp\git-on-BTSync>git init new-project Initialized empty Git repository in C:/temp/git-on-BTSync/new-project/.git/ C:\temp\git-on-BTSync>cd new-project C:\temp\git-on-BTSync\new-project>echo "" > README.txt git add . C:\temp\git-on-BTSync\new-project>git commit -m "Initial Commit" [master (root-commit) dcb3f2b] Initial Commit 1 file changed, 1 insertion(+) create mode 100644 README.txt
Create a new ‘bare’ repo inside of local BTSynced folder
new-project>mkdir C:\Users\jbetancourt\BTSync\git C:\new-project>git init --bare C:\Users\jbetancourt\BTSync\git\new-project.git Initialized empty Git repository in C:/Users/jbetancourt/BTSync/git/new-project.git/
Add this new bare repo as upstream remote to the local repo
new-project>git remote add dropbox C:\Users\jbetancourt\BTSync\git\new-project.git
Push local changes to the bare repo
C:\temp\git-on-BTSync\new-project>git push -u dropbox master Counting objects: 3, done. Writing objects: 100% (3/3), 223 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To C:\Users\jbetancourt\BTSync\git\new-project.git * [new branch] master -> master Branch master set up to track remote branch master from dropbox.
Use another system
On another system that is running BTSync, like a laptop, the bare repository folder is already synced. Now we can clone the repo.
cd \temp mkdir remote-workspace cd remote-workspace git clone -o dropbox \Users\jbetancourt\BTSync\git\new-project.git Cloning into 'new-project' ... done. cd new-project dir 11/29/2013 10:48 AM 5 README.txt
Now make some changes
On the laptop we modify a file and commit it.
echo "Hello world" > README.txt C:\temp\remote-workspace\new-project>type README.txt "Hello world" C:\temp\remote-workspace\new-project>git add README.txt C:\temp\remote-workspace\new-project>git commit -m "changed readme" [master 452b02e] changed readme 1 file changed, 1 insertion(+), 1 deletion(-)
Now push the changes to the local bare repo
C:\temp\remote-workspace\new-project>git push Counting objects: 5, done. Writing objects: 100% (3/3), 260 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To \Users\jbetancourt\BTSync\git\new-project.git dcb3f2b..452b02e master -> master
Back to the original repo on the PC
We pull the changes that were automatically synced via BTSync into
the bare repo.
type README.txt "" C:\temp\git-on-BTSync\new-project>git pull remote: Counting objects: 5, done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From C:\Users\jbetancourt\BTSync\git\new-project dcb3f2b..452b02e master -> dropbox/master Updating dcb3f2b..452b02e Fast-forward README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) C:\temp\git-on-BTSync\new-project>type README.txt "Hello world"
That was easy!
Issues with syncing git repos with BTSync?
- BitTorrentSync has been updated and now the process of syncing folders is either easier or harder, depending on you viewpoint. There are also some limitation for the free product, like ten folder limit.
- The machine having a source sync must be on to allow syncing, of course. Not true with a server based sync solution like Dropbox. This is only required while the local and remote folders are syncing of course. In many BTSync articles and blog posts the wrong impression is given that this is a continuous requirement. In fact, as soon as you see the sync complete, if you have the BTSync app visible you can shut down the source machine.
- Damage is also synced: If one of the synced repos gets damaged, that damage is reproduced in all correlated syncs. This can be prevented by using BTsync’s read only share feature. This would introduce some limitations or other complexities.
- Repository ignored files are synced
- There was a discussion on whether the .git folder should be synced. Not sure I follow the rational.
- I don’t know if there are any issues with BitTorrent Sync for long term work with a Git repo. People have complained of such issues with Dropbox. See the link for Mercurial use on DropBox below. In the comments of that blog post, robhamilton posts: “… found that it would break the Mercurial repo. Mercurial locks files and creates temp journal files which get sync’d by the dropbox daemon. My advice is to stop dropbox, perform your push/commit, then restart dropbox. Pulls and clones are readonly.” Is this an issue with Git? I don’t think so since we are using the bare repo approach.
- Dec 24, 2013: I did not investigate the mobile Git use with BTSync as shown above. BTSync has a mobile app that allows the sync to mobile devices. On that device a mobile Git client can access the synced bare repo to clone into a mobile local repo. There are now a few mobile Git clients, for example, SGit.
- June 26, 2015: Bittorrent Sync has an API: BitTorrent Gives Developers A Cloud-Free Alternative.
- Private P2P HSM, a network for optimal virtual storage
- Hierarchical Storage Management, from drive to cloud
- Using BitTorrent for large software deployments?
- BitTorrent Sync on mobile
- Source code control metadata shouldn’t sync by default
- BitTorrent Sync on WikiPedia
- BitTorrent Gives Developers A Cloud-Free Alternative
- Should I Use BitTorrent Sync Instead of Dropbox?
- Using Git with Dropbox
- The Next Big Thing You Missed: A Would-Be Dropbox Meant to Thwart the NSA
- Mercurial (hg) with Dropbox
- Sync your non-public code with Git and GoogleDrive
- Behind the scenes: The Making of BitTorrent Sync
- Git server on Windows? Gitblit open source, pure Java Git solution for managing, viewing, and serving Git repositories
- gitignore project on github
- BitTorrent reply to Hackito report on BitTorrent Sync’s bad crypto: No cause for concern
- Mobile music briefcase using BitTorrent Sync
- BitTorrent Sync on mobile
- BitTorrent sync: Unable to start updater process
- Single Developer Git Workflow
- Private P2P HSM, a network for optimal virtual storage