While git-annex can be installed on your Android device,
it might be easier not to install it there, but run it on your computer
using adb
to pull and push changes to the Android device.
A few reasons for going this route:
- Easier than installing git-annex on Android.
- Avoids needing to type commands into a terminal on Android.
- Avoids problems with putting a git-annex repository on Android's
/sdcard
, which is crippled by not supporting hard links etc.
All you should need is a USB cable (or adb over wifi), and the adb
command.
setting it up
First, initialize your git-annex repository on your computer, if you haven't already.
Then, in that repository, set up an adb special remote:
git-annex initremote android type=adb androiddirectory=/sdcard encryption=none exporttree=yes importtree=yes
The above example syncs with the /sdcard directory of the Android device. That can be a lot of files, so you may want a more limited directory. See the sample workflows below for some more examples.
Next, configure how trees of files imported from it will be merged into your git repository.
git config remote.android.annex-tracking-branch master:android
Setting "master:android" makes the phone be treated as containing a branch
of the master branch, and makes all its files appear to be inside a
subdirectory named android
. If you want its files to not be in a
subdirectory, set it to "master" instead.
Finally, you may want to configure a preferred content expression for the remote. That will limit both what is exported to it, and what is imported from it. If you want to fully sync all files, you don't need to do this.
For example, to limit the files that get imported and exported to sound files:
git annex wanted android 'include=*.mp3 or include=*.ogg'
syncing with it
git annex sync --content android
This command does a bi-directional sync with the phone, first importing new and changed files from it, merging that into the master branch, and then exporting from the master branch back to the android device so any modifications you have made get synced over to it.
See ?git-annex-import, [[git-annex-export, and git-annex-sync for more details, and bear in mind that you can also use commands like these to only import from or export to the android device:
git annex import master:android --from android
git annex merge android/master
git annex export master:android --to android
sample workflows
photos
Set up the remote to use the /sdcard/DCIM directory where the phone's camera stores them.
git-annex initremote android type=adb androiddirectory=/sdcard/DCIM encryption=none exporttree=yes importtree=yes
The annex-tracking-branch can be the same as before, to limit the files that are synced to those in an android directory:
git config remote.android.annex-tracking-branch master:android
If you don't want to keep old photos on your Android device, you can simply
git mv
the files from the android directory to another directory, and
the next sync with the phone will delete them from the Android device:
git mv android/* .
git annex sync --content
music and podcasts
You could set up the remote to use the /sdcard/Music directory. But, I sometimes download music to other locations, and perhaps you do too. Let's instead limit the remote to mp3 and ogg files:
git-annex initremote android type=adb androiddirectory=/sdcard encryption=none exporttree=yes importtree=yes
git annex wanted android 'include=*.mp3 or include=*.ogg'
The annex-tracking-branch can be the same as before, to limit the files that are synced to those in an android directory:
git config remote.android.annex-tracking-branch master:android
And then do an initial sync:
git annex sync --content android
Now, you can copy music and podcasts you want to listen to over to the Android device, by first copying them to the android directory of your git-annex repo:
cp -a podcasts/LibreLounge/Episode_14__Secure_Scuttlebutt_with_Joey_Hess.ogg android/
git annex add android
git annex sync --content android
That will also import any new sound files from the Android device into your git-annex repo.
Once you're done with listening to something on the Android device, you can simply delete it from the device, and the next time git-annex syncs, it will get removed from the android directory. Or, you can delete it from the android directory and the next sync will delete it from the Android device.
I did that. Than I issued:
which downloaded a lot of files
Then:
git annex merge android/master merge android/master merge: android/master - not something we can merge failed git-annex: merge: 1 failed
I tried different combinations of android/master, ./master, master/. , but all seem to fail.
plain git status shows a lot of non-added files for an "initial commit", and no files added. git annex status lists a lot of
files.
Any suggestions?
At which point should I do ordinary git commits?
So far the repo has been at just the "Initial commit"
git-annex import master --from android
should have created an android/master branch with the imported files in it. There is apparently no such branch in your case.But I see that you also posted ?strong> where you talk about having interrupted the import before it was complete. Since the branch only gets created when the import is allowed to finish, I think that explains your problem.
It's rarely a good idea to not fully explain what you actually did when reporting what seems like a problem. If I had not happened to read that forum post first, and noticed it was also from you, we would have embarked on a snipe hunt to find some bug that doesn't really exist.
Well, how would I know that that was significant? I resumed the import after interrupting it and let it run till it finished (several days actually).
In fact, I let "import" run several times till the end, the first time taking a lot of time, and the next ones taking ~10 minutes each.
Indeed, there seems to be no android_cable/master branch
I tried to create the branch manually, but there seems to be no
git-annex branch
.In addition, this post is easily googleable, whereas "forum" is not. I believe that documenting a typical-of-the-typical issue that a user may encounter at the place which if the point of the first consultation is fairly useful.
How do I manually create this android_cable/master remote branch?
For the sake of testing, I created another remote on the same smartphone, and indeed, if "import" finishes in one try, there is a
How do I find an object that corresponds to the original
android_cable
special remote?This tip seems to work just fine when I try it. After
git annex sync --content android
, it had merged the remotes/android/master branch in. So I don't think there's a general problem with this tip that needs to be discussed here.The remote tracking branch is created or updated every time git-annex imports from the android remote, eg every time that sync command is run.
If it's not creating it for you, you might have run into a bug, but if so you'll need to work out how others can reproduce it, and file a bug report.
Desired workflow with "adb":
Concerns:
So, maybe expressions for "wanted content on remote" and "completely ignored in ALL remotes" must be two different options? However the current behavior of this "ignored" thing is too much counter-intuitive, making its existence questionable. Otherwise how can I accomplish abovementioned workflow i.e. make "adb special remote" to visibly behave during sync as regular annex repo w/o listed quirks?
Hello, some time ago (it was Jan 2022) I set up an adb remote like explained here and I was able to sync multiple times with my phone.
After some time with no syncs, today I'm trying to sync again but I get this error:
My doubt is that something changed when I upgraded git-annex, this is my currently installed version:
Please do you have any hint on what I should do to make this running again?
Thanks! Giovanni
@g, when you have a problem like this, don't post a comment to a random place. File a bug report!
In this case, someone else has filed a bug: adb remote fails to import treeish
androiddirectory=/
, thengit annex wanted thephone 'include=/storage/self/primary/DCIM and include=/storage/33A8-601A/DCIM'
(I guess a trailing/*
would have been necessary in addition), but that gives a gigantic amount offind: [...] read/permission denied
errors upon import (I canceled it) and I guess as it traverses the entire file tree, it is very inefficient.