3

I had created created repository in UNIX machine,

$sudo git --bare init /var/repos/git/repo00001

Also I have done following commands executed for individual UNIX users,

$ git config --global user.email "MyfullName@mindtree.com"
$ git config --global user.name "Anand Sadasivam"

Under which directory I should be creating git repsitories, I have issue while check-in files. What should be the permission, user, group needs to be set for directory /var/repos/git on under which I am creating git repositories. At present its done under root privilege. Do I need to create separate UNIX user for git exclusively or any specific step or git command I have to follow to create user first before creating repository with git init

I had observed --bare for init created some basic structure under git repository. But when I did git clone my repository was empty.

Since I had used --bare, I could see folder structure created as follows,

# ls
HEAD  branches  config  description  hooks  info  objects  refs

Following are the commands I have done at git bash client side in Windows for initial check-in of some file,- Readme.txt

$ git clone anand@xx.xx.xx.xxx:/var/repos/git/repo00001
Cloning into 'repo00001'...
anand@xx.xx.xx.xxx's password:
warning: You appear to have cloned an empty repository.

<<I had created Readme.txt file under the present directory>>

$ git add Readme.txt

$ git status
On branch master

$ git commit -a
[master (root-commit) 8201309] Initial commit
 Committer: Anand Sadasivam <MMyEmpID@mindtree.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 create mode 100644 Readme.txt

$ git push origin master
anand@xx.xx.xx.xxx's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 240 bytes | 120.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
error: remote unpack failed: unable to create temporary object directory
To xx.xx.xx.xxx:/var/repos/git/repo00001
 ! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'anand@xx.xx.xx.xxx:/var/repos/git/repo00001'

$ git show-ref
82013098f6801ea32bb620b612f779c8dade6d83 refs/heads/master

$ git push origin HEAD:master
anand@xx.xx.xx.xxx's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 240 bytes | 120.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
error: remote unpack failed: unable to create temporary object directory
To xx.xx.xx.xxx:/var/repos/git/repo00001
 ! [remote rejected] HEAD -> master (unpacker error)
error: failed to push some refs to 'anand@xx.xx.xx.xxx:/var/repos/git/repo00001'

Is this situation had arisen because Windows Settings been followed while git bash/gui client installation.

Or it is completely repository permission issue or repository creation user issue in UNIX

Dev Anand Sadasivam
  • 699
  • 7
  • 21
  • 49
  • 1
    Your problems start the moment when you use `sudo`. `sudo` is a system tool that must be used **only to modify the system configuration**. Git is not a system configuration. Using Git (or any other tool you usually use for development) with `sudo` is **not needed** and it causes (most of) your troubles. – axiac Apr 20 '18 at 06:32
  • Now I had created user by name `git` in `UNIX` machine. On that account I did `git init --bare`. Repository folder has `group and user` is been set as `git`. And for others there is no `write` permission. So again, these problem persist as I'm using different user for `git clone` – Dev Anand Sadasivam Apr 20 '18 at 06:55
  • For `group`, repository which is created by the command with option `--bare` has `rw` access. On that basis I have added `UNIX users` who needs access that repository to that `group`. That made my `git` repository functional. – Dev Anand Sadasivam Apr 25 '18 at 09:02
  • This is the solution, indeed. Post it as an answer. – axiac Apr 25 '18 at 09:04
  • Not only that `--shared` must've been used with `--bare init`. – Dev Anand Sadasivam May 08 '18 at 07:18
  • Else `git push` gives some trouble, also `chmod -R g+wX` not helps when we try for `repository` folder created by `--bare init` – Dev Anand Sadasivam May 08 '18 at 07:20

1 Answers1

3

Repository should be created with --bare init --shared, I mean shared option should be additional and it should be done under,- say git login and sudo command must not be used. Once repository is created it will have rw access to group users.

git@xx-xx-xx-xxx~/repos/repo00001$ ls -l
total 32
-rw-rw-r--  1 git git   23 Apr 20 06:44 HEAD
drwxrwxr-x  2 git git 4096 Apr 20 06:44 branches
-rw-rw-r--  1 git git   66 Apr 20 06:44 config
-rw-rw-r--  1 git git   73 Apr 20 06:44 description
drwxrwxr-x  2 git git 4096 Apr 20 06:44 hooks
drwxrwxr-x  2 git git 4096 Apr 20 06:44 info
drwxrwxr-x 62 git git 4096 Apr 25 08:22 objects
drwxrwxr-x  4 git git 4096 Apr 20 06:44 refs

Hence I have added all the users who needs to work with git repository to the group git, as you can see git:git is created repository and group git has rwx for most of the folder under which revisions going to be maintained.

I've added & verified if the user is added to group,- git

anand@capsimt00001:~$ sudo usermod -a -G git anand
anand@capsimt00001:~$ groups
anand geckoo git

groups command displays all the group that particular user is belongs too.

Dev Anand Sadasivam
  • 699
  • 7
  • 21
  • 49
  • Now for cloning, I'm using `git clone anand@xx.xx.xx.xxx:/home/git/repos/repo00001` – Dev Anand Sadasivam Apr 25 '18 at 11:00
  • If you are accessing from Windows,- local system,— **Eclipse IDE**, you need to update **private key** `id_dsa,id_rsa` files. These files you can create under your UNIX ssh logins, by generating it using `ssh-keygen` command and with option `-t DSA` dsa key-pair. Private key files `id_dsa,id_rsa`, you can find it under `.ssh` folder in `HOME` directory. – Dev Anand Sadasivam Apr 25 '18 at 12:28
  • Answer [--shared option and chmod -R g+wX repo-dir](https://stackoverflow.com/questions/685319/git-pull-error-unable-to-create-temporary-sha1-filename/2912558#2912558) must be followed to work out with repository in `group`. – Dev Anand Sadasivam May 08 '18 at 07:22
  • And now I have repository in `/var` folder,- `/var/repos/repo00001`. Permissions I've adjusted accordingly to match for git repository `user` with command `chown -R user:group user_dir`. Creating repository under `HOME` have some implication I think. – Dev Anand Sadasivam May 08 '18 at 07:54
  • `push to upstream` fails basically, and once it happens, we may have to do `git repack`, `git gc`. I think `push branch master` succeeds, when we collapse and do the other one, consecutive attempts fails, this try I did in — **_Eclipse IDE_** – Dev Anand Sadasivam May 08 '18 at 08:11