55

(Solved already, I'm writing this for the next guy)

I was running git daemon on one computer and tried synchronizing with another.

On computer A, I ran:

git daemon --reuseaddr --base-path=. --export-all --verbose

On computer B, I ran:

git clone git://computerA/.git source # worked
cd source
git pull # worked
git push # failed with "fatal: The remote end hung up unexpectedly"

On computer A, the daemon output is:

[5596] Connection from 127.0.0.1:2476
[5596] Extended attributes (16 bytes) exist <host=localhost>
[5596] Request receive-pack for '/.git'
[5596] 'receive-pack': service not enabled for './.git'
[5444] [5596] Disconnected (with error)

I'm going to post the soultion I found. If you have a more complete answer, please go ahead and add it.

itsadok
  • 28,822
  • 30
  • 126
  • 171
  • anyone using msysgit daemon on windows 'wanna know about the `sendpack.sideband` config-option at https://github.com/msysgit/git/issues/101#issuecomment-46114024 or alternatively use [Git-1.7.4.rc1.3197.gbf965](https://code.google.com/p/msysgit/issues/detail?id=457#c62) (a [more direct link](https://onedrive.live.com/?cid=624606b9c3176d53&id=624606B9C3176D53!4848&authkey=!ANl5kSH_bExkzrk) here) – n611x007 Jun 18 '14 at 19:01

3 Answers3

62

Simply run

git daemon --reuseaddr --base-path=. --export-all --verbose --enable=receive-pack

(on computer A, instead of the original git daemon command), and the push works.

Note that you have to then run

git reset --hard

on computer A to make it "see" the changes from computer B.

Post Script

The problem with doing a hard reset is that it overwrites whatever local changes you had on computer A.

Eventually I realized it would make much more sense to have a separate repository (a bare clone) that doesn't have any files in it, then have computer B push to it and computer A pull from it. This way it can work both ways and merge all the changes in a smooth fashion. You can even have two bare clones, one on each computer, and push-pull between them.

Community
  • 1
  • 1
itsadok
  • 28,822
  • 30
  • 126
  • 171
  • 3
    Is there anything I can do to not have to run `git reset --hard` after a push to see the changes? – Rohit Jul 08 '09 at 20:27
  • 1
    Depends on why you don't want to run it. If you just want to minimize typing, you can set up a hook (check out http://utsl.gen.nz/git/post-update for an example). Otherwise, see my PS. – itsadok Jul 09 '09 at 06:44
  • I am using the other (non bare) repository as a backup on a mounted NAS. I could set up a simple backup script but that had some other problems. I'll check out the the hook thing and your script. Thanks a lot! – Rohit Jul 09 '09 at 13:31
  • @Rohit If you're having issues pushing to a non-bare repository, try checking out another branch before pushing. If you're just using it as a backup, you'll always be able to check out your original branch in the future. I guess we don't really understand your problem domain. Maybe ask your question more fully in it's own Stack Overflow question. – Tim Snowhite May 30 '11 at 16:34
  • Can you not `git stash` your local changes, then do a hard reset and pop your stash? – Tim Keating Apr 15 '13 at 21:26
24

I encountered this error, but the solution seems different for those using git-http-backend. (git push/pull/clone over http instead of ssh or git)

This must be done on the remote server, and is best done on creation. (last line can be run independently if repo already exists / is in use)

$ mkdir eddies  # MAKE folder for repo
$ chown -R eddie:websrv eddies/  #ensure apache (webserver) can access it
$ cd eddies/
$ git --bare init --shared
Initialized empty shared Git repository in /var/git/eddies/
$ ls
branches  config  description  HEAD  hooks  info  objects  refs
$ git config --file config http.receivepack true
Eddie
  • 9,696
  • 4
  • 45
  • 58
  • 4
    YOu can also add SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER to your apache config aparrently to get around this command. – Eddie Aug 22 '11 at 16:55
  • 2
    See the full solution http://stackoverflow.com/questions/3947530/git-push-fatal-failed/7177690#7177690 – Eddie Aug 24 '11 at 15:50
  • This is the solution that solved my issue (had existing local repo, created bare remote repo on windows server, trying to push via http, getting 403 error) – Dale Smith Jan 07 '13 at 15:40
6

I have some issue with the git reset --hard so here is my alternative solution.

On the local cloned repo make a branch

git checkout -b my_new_branch

on the remote origin repo enable the receive-pack service

git daemon --reuseaddr --base-path=. --export-all --verbose --enable=receive-pack

push the new branch to remote origin

git push origin my_new_branch

merge the new branch on origin with

git merge my_new_branch
Ben
  • 13,297
  • 4
  • 47
  • 68