[英]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. 我正在尝试在本地计算机上设置一个Git存储库,以便在本地计算机上完成工作-没有远程操作。
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
我有2个目录:
/home/rico/project
和/home/git/project_repo
I've created the git user to manage all my git repos (I expect to have dozens). 我创建了git用户来管理我所有的git仓库(我希望有几十个)。
From /home/rico/project
as the rico
user I do the following command: 从
/home/rico/project
以rico
用户身份执行以下命令:
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: 从
/home/git/project_repo
作为git
用户,我执行以下操作:
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. 这时我得到正常的提交消息-
23 files changed, 989 insertions(+)
等。
Now, I want to push this to the project_repo
folder. 现在,我想将其推送到
project_repo
文件夹。
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: 甚至使用我的本地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.
它要求输入密码,我知道我提供的密码正确,并且不断收到消息“
Permission denied, please try again.
I just want to be able to push my project
to my project_repo
. 我只希望能够将我的
project
推送到我的project_repo
。 What am I doing wrong in this setup? 在此设置中我在做什么错?
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
: 然后,我可以在
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. 我真的不喜欢给任何东西提供
777
的想法。 Should I put git
and rico
in the same group and do 775
instead? 我应该把
git
和rico
放在同一个组中,而不是做775
吗?
Any suggestions? 有什么建议么?
EDIT1: Putting git
and rico
in the same group and doing 775
did not help. 编辑1:将
git
和rico
放在同一组中并执行775
并没有帮助。 It works fine with 777
but I don't like this solution. 它在
777
可以正常工作,但我不喜欢这种解决方案。
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.
在比较了几十个标题为“ howtos”的“小菜一碟”之后,我找出了主要问题。 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.
在编辑〜/ .ssh / config后,如下所示的方式像一个超级按钮一样起作用。
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". 在此示例中,服务器主机称为gitolite ,用于在服务器上安装gitolite的特殊帐户称为git ,客户端上的用户名为harrie ,/ home / harrie / .ssh中的密钥对由“ ssh- keygen-t rsa -f harrie”。
~/.ssh/config 的〜/ .ssh /配置
Host gitolite
User git
Hostname gitolite
Port 22
IdentityFile ~/.ssh/harrie
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.