Git push is finicky

2019-06-05 14:03发布

问题:

I have been having a lot of issues using git (also, I'm a newb). Many times when I try to git push I run into errors. See below:

Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 6.03 KiB | 0 bytes/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: error: insufficient permission for adding an object to repository database ./objects
remote: fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To /Volumes/batcave/sourceControl/x.git
 ! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to '/Volumes/batcave/sourceControl/x.git'

The strange part about this is if I type:

git reset --hard origin/master

then

emacs testfile.txt

and enter text into the testfile.txt then do the usual:

git add .
git commit -a -m"added testfile.txt"
git push

that push works. So I don't buy it's that I don't have the proper permission. Also, sometimes if I just open the file that I was having problems pushing in emacs and add and delete some returns, then it works.

For further information, I'm using the git repository to keep my desktop pc and mac laptop synchronized.

回答1:

You are crossing permissions models between systems with what appears to be a mounted filesystem. This is inadvisable when the systems are as different as Mac OS and windows. When you are pushing you are writing new files and modifying indexes. By accessing via share, you are likely attempting those operations as a differently permissioned user. Instead you should be using a network protocol between the two systems so that the file operations are always executed from the same context.

If the code is stuff you don't mind being public anyway, the quickest approach would be to use an existing free git server like github. Both systems would pull and push from the host. This is my recommendation.

Otherwise, pick one system to be your "server" and set up SSH key-based authentication between the two systems so that the git protocol is used for access. Essentially this means that the client system should access the server as the user@server that owns the repo files. (It is also possible, though probably unnecessary to set up the two symmetric to each other such that both could push or pull, using SSH authorized_keys on both sides.)



标签: git push