简体   繁体   中英

Setting up a local git repository on Ubuntu

I'm trying to setup a Git repo on my local machine for work that is being done on my local machine - no remote anything.

I've setup remote repos several times but it seems the steps I take locally always end up with errors.

I have 2 directories: /home/rico/project and /home/git/project_repo

I've created the git user to manage all my git repos (I expect to have dozens).

From /home/rico/project as the rico user I do the following command:

rico@verbal:~/project$ git init
Initialized empty Git repository in /home/rico/project/.git/

From /home/git/project_repo as the git user I do the following:

git@verbal:~/project_repo$ git --bare init
Initialized empty Git repository in /home/git/project_repo

Now I go back to my project and add files.

rico@verbal:~/project$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .project
#       .pydevproject
#       inc/
#       manage.py
#       rocksolidbox/
#       rsb/
#       templates/
rico@verbal:~/project$ git add inc media rocksolidbox/ rsb/ templates/
rico@verbal:~/project$ git commit -a -m "Initialize the project."

At this point I get the normal commit message - 23 files changed, 989 insertions(+) etc.

Now, I want to push this to the project_repo folder.

rico@verbal:~/project$ git remote add origin /home/git/rocksolidbox/
rico@verbal:~/project$ git push -u /home/git/rocksolidbox/ master

But receive the following error:

Counting objects: 31, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (26/26), done.
error: insufficient permission for adding an object to repository database ./objects

fatal: failed to write object
Writing objects: 100% (31/31), 12.24 KiB, done.
Total 31 (delta 2), reused 0 (delta 0)
error: unpack failed: unpack-objects abnormal exit
To /home/git/project_repo/
 ! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to '/home/git/project_repo/'

Clearly this is a permissions error. I've tried to do the push such as:

rico@verbal:~/project$ git push -u git@verbal:/home/git/rocksolidbox/ master

Or even using my local IP:

rico@verbal:~/project$ git push -u git@192.168.1.101:/home/git/rocksolidbox/ master

It asks for a password, which I know I'm supplying correctly and I continually get the message Permission denied, please try again.

I just want to be able to push my project to my project_repo . What am I doing wrong in this setup?

Don't do all that fancy permissions footwork. You want gitolite .

Ok, I've figured out a way around the permissions problem. Basically do this:

git@verbal:~/$ chmod -R 777 project_repo

Then I can do the following commands with my project :

rico@verbal:~/project$ git remote add origin /home/git/project_repo/
rico@verbal:~/project$ git push -u /home/git/project_repo/ master

Then to clone the project elsewhere simply do:

rico@verbal:~/some_other_location$ git clone /home/git/project_repo

And you're golden.

Now, my question remains...is this the best way of handling the permissions problem? I don't really like the idea of giving 777 to anything. Should I put git and rico in the same group and do 775 instead?

Any suggestions?

EDIT1: Putting git and rico in the same group and doing 775 did not help. It works fine with 777 but I don't like this solution.

I got stuck at the same point. "Something has gone wrong" isn't very informative so far. After comparing dozens of "it's a piece of cake"-titled howtos I figured out the main problem. Most of the examples have client and server on the same host. That's not what I wanted. After editing the ~/.ssh/config the way shown below it worked like a charm.

For this example the server host is known as gitolite , the special account for installing gitolite on the server is called git , the user on the client is named harrie and the keypair in /home/harrie/.ssh has been generated by "ssh-keygen-t rsa -f harrie".

~/.ssh/config

Host gitolite
        User git
        Hostname gitolite
        Port 22
        IdentityFile ~/.ssh/harrie

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM