### Please describe the problem.

I use both the assistant and the command line. Unfortunately I often end up
in a state where I cannot do a "git annex sync" (it fails as described below)
and I have to use the assistant to synchronize things to make the sync work. I
would like to know how to do the same thing using only the command line.

### What steps will reproduce the problem?

This problem involves two repos: a local, indirect mode, manual group, repo, and
a ssh remote archive group bare repo (with full git annex available
remotely). The local repo is "top" and the remote one is "mini_archive".

I start with the assistant not running, and the two repos in sync. Note that the
remote server cannot directly contact the local repo.

local:

    schmitta@top ~/D/annex (master)> git annex sync
    commit
    ok
    pull mini_archive 
    ok

remote:

    schmitta@mini ~/a/archive> git annex sync
    commit
    ok

I then add a file locally and try to sync, getting a problem on mini_archive:

    schmitta@top ~/D/annex (master)> git annex add videos/Minecraft/Icy\ and\ FlowerChild\ Play\ -\ Better\ Than\ Wolves\ 3-qg6LVTcDl4Y.mp4 
    add videos/Minecraft/Icy and FlowerChild Play - Better Than Wolves 3-qg6LVTcDl4Y.mp4 (checksum...) ok
    (Recording state in git...)
    schmitta@top ~/D/annex (master)> git annex sync
    commit
    ok
    pull mini_archive 
    ok
    push mini_archive 
    Counting objects: 15, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (10/10), done.
    Writing objects: 100% (10/10), 1.01 KiB | 0 bytes/s, done.
    Total 10 (delta 4), reused 0 (delta 0)
    remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)
    To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
       a5b002b..dde2626  master -> synced/master
     ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
    error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
    failed
    git-annex: sync: 1 failed

I try to merge and sync on the remote (I assume sync also does merge, but I'm
not sure).

    schmitta@mini ~/a/archive> git annex merge
    merge git-annex ok
    schmitta@mini ~/a/archive> git annex sync
    commit
    ok

Back on the local machine, I still have the conflict.

    schmitta@top ~/D/annex (master) [1]> git annex sync
    commit
    ok
    pull mini_archive 
    ok
    push mini_archive 
    Counting objects: 7, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (5/5), done.
    Writing objects: 100% (5/5), 513 bytes | 0 bytes/s, done.
    Total 5 (delta 1), reused 0 (delta 0)
    remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)
    To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
     ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
    error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
    failed
    git-annex: sync: 1 failed

From this state, the only way to resolve things is to launch the web app. It
tells me "synced with mini_archive" (and it starts uploading the new file). Then
on the server there is something to merge. (I haven't waited for the file to
finish uploading in this case.)

    schmitta@mini ~/a/archive> git annex merge
    merge git-annex (merging refs/synced/1cdfb490-0660-41fb-b7ce-74b89abb9aac/git-annex into git-annex...)
    ok
    schmitta@mini ~/a/archive> git annex sync
    commit
    ok

and I can then sync on the local repo:

    schmitta@top ~/D/annex (master) [1]> git annex sync
    commit
    ok
    pull mini_archive 
    From ssh://git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive
       8f39d4c..cb7f6c3  git-annex  -> mini_archive/git-annex
    ok

Note that I need to do the remote merge for things to work. After the file has
finished uploading, I get back in a conflict:

    schmitta@top ~/D/annex (master)> git annex sync
    commit
    ok
    pull mini_archive 
    ok
    push mini_archive 
    Total 0 (delta 0), reused 0 (delta 0)
    remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)
    To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
     ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
    error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
    failed
    git-annex: sync: 1 failed

If I disable and re-enable the sync on the server (forcing a sync), I still have
a conflict locally:

    schmitta@top ~/D/annex (master) [1]> git annex sync
    commit
    ok
    pull mini_archive 
    ok
    push mini_archive 
    Total 0 (delta 0), reused 0 (delta 0)
    remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)
    To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
     ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
    error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
    failed
    git-annex: sync: 1 failed

It only get solved by doing a merge on the server:

    schmitta@mini ~/a/archive> git annex merge
    merge git-annex (merging refs/synced/1cdfb490-0660-41fb-b7ce-74b89abb9aac/git-annex into git-annex...)
    (Recording state in git...)
    ok

    schmitta@top ~/D/annex (master) [1]> git annex sync
    commit
    ok
    pull mini_archive 
    remote: Counting objects: 13, done.
    remote: Compressing objects: 100% (5/5), done.
    remote: Total 5 (delta 3), reused 0 (delta 0)
    Unpacking objects: 100% (5/5), done.
    From ssh://git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive
       cb7f6c3..d177e1a  git-annex  -> mini_archive/git-annex
    ok
    (merging mini_archive/git-annex into git-annex...)


### What version of git-annex are you using? On what operating system?

Current version available on cabal:

    schmitta@top ~/D/annex (master)> git annex version
    git-annex version: 4.20131002
    build flags: Assistant Webapp Pairing Testsuite S3 WebDAV FsEvents XMPP DNS Feeds Quvi
    key/value backends: SHA256E SHA1E SHA512E SHA224E SHA384E SKEIN256E SKEIN512E SHA256 SHA1 SHA512 SHA224 SHA384 SKEIN256 SKEIN512 WORM URL
    remote types: git gcrypt S3 bup directory rsync web webdav glacier hook
    local repository version: 3
    default repository version: 3
    supported repository versions: 3 4
    upgrade supported from repository versions: 0 1 2

    schmitta@mini ~/a/archive> git annex version
    git-annex version: 4.20131002
    build flags: Assistant Webapp Pairing Testsuite S3 WebDAV FsEvents XMPP DNS Feeds Quvi
    key/value backends: SHA256E SHA1E SHA512E SHA224E SHA384E SKEIN256E SKEIN512E SHA256 SHA1 SHA512 SHA224 SHA384 SKEIN256 SKEIN512 WORM URL
    remote types: git gcrypt S3 bup directory rsync web webdav glacier hook
    local repository version: 3
    default repository version: 3
    supported repository versions: 3 4
    upgrade supported from repository versions: 0 1 2


### Please provide any additional information below.

Here is daemon.log. It mentions another repo which is an external
hard drive not plugged it at the moment. I'm skipping the file transmission
(...).

[[!format sh """
# If you can, paste a complete transcript of the problem occurring here.
# If the problem is with the git-annex assistant, paste in .git/annex/daemon.log

[2013-10-23 14:02:05 CEST] main: starting assistant version 4.20131002
[2013-10-23 14:02:05 CEST] TransferScanner: Syncing with hole, mini_archive 
Already up-to-date.
fatal: '/Volumes/hole/annex/' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

(scanning...) [2013-10-23 14:02:06 CEST] Watcher: Performing startup scan
Already up-to-date.
Already up-to-date.
fatal: '/Volumes/hole/annex/' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)[K
To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
 ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
fatal: '/Volumes/hole/annex/' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: '/Volumes/hole/annex/' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)[K
To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
 ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
fatal: '/Volumes/hole/annex/' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
[2013-10-23 14:02:10 CEST] Committer: Committing changes to git
[2013-10-23 14:02:10 CEST] Pusher: Syncing with mini_archive 


(Recording state in git...)
(started...) To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
   8f39d4c..cb7f6c3  git-annex -> refs/synced/1cdfb490-0660-41fb-b7ce-74b89abb9aac/git-annex
   a5b002b..dde2626  master -> refs/synced/1cdfb490-0660-41fb-b7ce-74b89abb9aac/master
remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)[K
To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
 ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)[K
To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
 ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
Everything up-to-date
(gpg) 


SHA256E-s608232213--d4d6e02e651b1d265ff1c041ee8e8c23db9d880140816d62b8cc82cee4db3a54.mp4

...

sent 608306626 bytes  received 42 bytes  5133389.60 bytes/sec
total size is 608232213  speedup is 1.00
[2013-10-23 14:04:13 CEST] Transferrer: Uploaded Icy and F..cDl4Y.mp4
[2013-10-23 14:04:13 CEST] Pusher: Syncing with mini_archive 
remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)[K
To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
 ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)[K
To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
 ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
   cb7f6c3..927cc1c  git-annex -> refs/synced/1cdfb490-0660-41fb-b7ce-74b89abb9aac/git-annex
[2013-10-23 14:05:35 CEST] main: Syncing with mini_archive 
remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)[K
To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
 ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
remote: error: denying non-fast-forward refs/heads/synced/git-annex (you should pull first)[K
To ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/
 ! [remote rejected] git-annex -> synced/git-annex (non-fast-forward)
error: failed to push some refs to 'ssh://schmitta@git-annex-**.**.**.**-schmitta_annex.2Farchive/~/annex/archive/'
Everything up-to-date


# End of transcript or log.
"""]]

> So, receive.denyNonFastforwards was the problem. It turns out that
> `git init --bare --shared` sets that by default, and the webapp
> uses that to create repositories on ssh server. I have made the webapp
> unset receive.denyNonFastforwards when setting up such a repository.
> 
> Also added something to the assistant release notes about this
> to handle existing repositories. [[done]] --[[Joey]]
