Sync Hacks is a column dedicated to exploring new applications for Sync, as built by users like you. BitTorrent Sync is a free, unlimited, secure file-syncing app. (And now, it’s 2X faster.) If you’ve got an epic Sync idea, use-case or how-to, shoot us an email at sync[at]bittorrent.com.
In this week’s Sync Hacks: Josef Betancourt shows us how to use Git with BitTorrent Sync. Josef turned to BitTorrent Sync because Sync gives you the benefits of having a remote Git server without using a remote server – maintaining multiple copies all on your own machines. Now, he wants to show you how to get started. Read on for the whole tutorial (adapted from his original post here).
In this post, you’ll find simple instructions for using Git with BitTorrent Sync on Windows. 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.
While cloud-based solutions provide a good way to backup or remote a Git repository for ‘single developer’ situations, the main advantages of BitTorrent Sync is that it’s free and no ‘server’ is required. Described briefly: BitTorrent Sync is a server-less 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 or your backup system, but it is a welcome addition as it covers some limitations of those services, such as file size limits, and issues with speed and privacy.)
What we’ll do:
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.
Once complete, the synced folder that contains the bare repo is available on another system as if it was created locally. During development, the synced folder does not constantly transfer data over the network to other synced locations because we primarily use the working repo and rarely use the ‘bare’.
The picture below shows two systems with the two Git repos:
Below is a walkthrough of this process using a Windows cmd shell.
Create a local repository
C:tempgit-on-BTSync>git init new-project Initialized empty Git repository in C:/temp/git-on-BTSync/new-project/.git/ C:tempgit-on-BTSync>cd new-project C:tempgit-on-BTSyncnew-project>echo "" > README.txt git add . C:tempgit-on-BTSyncnew-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 BitTorrent Sync folder
new-project>mkdir C:UsersjbetancourtBTSyncgit C:new-project>git init --bare C:UsersjbetancourtBTSyncgitnew-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:UsersjbetancourtBTSyncgitnew-project.git
Push local changes to the bare repo
C:tempgit-on-BTSyncnew-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:UsersjbetancourtBTSyncgitnew-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 BitTorrent Sync, 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 UsersjbetancourtBTSyncgitnew-project.git Cloning into 'new-project' ... done. cd new-project dir 11/29/2013 10:48 AM 5 README.txt
On this other system, modify a file and commit it.
echo "Hello world" > README.txt C:tempremote-workspacenew-project>type README.txt" Hello world" C:tempremote-workspacenew-project>git add README.txt C:tempremote-workspacenew-project>git commit -m "changed readme" [master 452b02e] changed readme 1 file changed, 1 insertion(+), 1 deletion(-)
Push the changes to the local bare repo
C:tempremote-workspacenew-project>git push Counting objects: 5, done. Writing objects: 100% (3/3), 260 bytes, done. Total 3 (delta 0), reused 0 (delta 0) To UsersjbetancourtBTSyncgitnew-project.git dcb3f2b..452b02e master -> master
Back to the original repo on the PC
Pull the changes that were automatically synced via BitTorrent Sync into
the bare repo.
type README.txt "" C:tempgit-on-BTSyncnew-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:UsersjbetancourtBTSyncgitnew-project dcb3f2b..452b02e master -> dropbox/master Updating dcb3f2b..452b02e Fast-forward README.txt | 2 +-1 file changed, 1 insertion(+), 1 deletion(-) C:tempgit-on-BTSyncnew-project>type README.txt "Hello world"
All done. That was easy!
Issues with syncing git repos with BitTorrent Sync?
• The machine with the source sync must be on to allow syncing. This is not true with a server-based sync solution like Dropbox.
• Damage is also synced: If one of the synced repos gets damaged, that damage is reproduced in all correlated syncs
• 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 this post about Mercurial use on DropBox. In the comments of that blog post, robhamilton “… found that it would break the 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 read only.” Is this an issue with Git?
• Using BitTorrent for large software deployments?
• Source code control metadata shouldn’t sync by default
• BitTorrent Sync on WikiPedia
• Using Git with Dropbox
• Mercurial (hg) with Dropbox
• Sync your non-public code with Git and GoogleDrive
• BitTorrent Sync on mobile
• 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
Josef Betancourt is a software developer and also does configuration management.