linux – Problem with git in local

Question:

I have a virtual machine with ubuntu where I have git installed as a server and another with ubuntu that I use as a client. I start the repository on the server and then on the client. In the client I indicate the files with add. , I do the commit, and I push indicating the server's repository:

git push ssh://git@192.168.0.120/home/alberto/git/app master

So that I don't get an error when pushing the server I have to put:

git config receive.denyCurrentBranch ignore

Once you have done it, the files in the / home / alberto / git / app directory are not created on the server. Why are they not created?

Why do I have to use receive.denyCurrentBranch ignore in server repository?

any help, thank you very much

Client 192.168.0.102:

root@serverproject:/var/www/html/email# git init
Initialized empty Git repository in /var/www/html/email/.git/
root@serverproject:/var/www/html/email# git add .
root@serverproject:/var/www/html/email# git status
En la rama master

Commit inicial

Cambios para hacer commit:
  (use <<git rm --cached <archivo>...>> para sacar del stage)

    nuevo archivo: ._email.class.php
    nuevo archivo: correos.txt
    nuevo archivo: email.class.php
    nuevo archivo: lib/class.phpDataClass.php
    nuevo archivo: lib/class.phpmailer.php
    nuevo archivo: lib/class.pop3.php
    nuevo archivo: lib/class.smtp.php

root@serverproject:/var/www/html/email# git commit -m "first commit"
[master (root-commit) a86c2c9] first commit
 7 files changed, 4389 insertions(+)
 create mode 100755 ._email.class.php
 create mode 100755 correos.txt
 create mode 100755 email.class.php
 create mode 100755 lib/class.phpDataClass.php
 create mode 100755 lib/class.phpmailer.php
 create mode 100755 lib/class.pop3.php
 create mode 100755 lib/class.smtp.php
root@serverproject:/var/www/html/email# git remote add origin ssh://git@192.168.0.120/home/alberto/git/email
root@serverproject:/var/www/html/email# git push -u origin master
git@192.168.0.120's password: 
Counting objects: 10, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 34.20 KiB | 0 bytes/s, done.
Total 10 (delta 0), reused 0 (delta 0)
To ssh://git@192.168.0.120/home/alberto/git/email
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
root@serverproject:/var/www/html/email# git status
En la rama master
Su rama est? actualizada con <<origin/master>>.
nothing to commit, working directory clean
root@serverproject:/var/www/html/email# 

Server 192.168.0.120:

$ git init
Initialized empty Git repository in /home/alberto/git/email/.git/
$ git config receive.denyCurrentBranch ignore
$ ls
$ ls -a
.  ..  .git
$ 

Answer:

Traditionally, a git repository that you want to push was not a normal repository. It was a repository that had no "working copy".

As I suppose you know, the working copy is the folder that contains the files, other folders, etc. over which you are keeping version control. In addition to the working copy, the git repositories have another folder called .git (hidden by starting with a period) where all the history is stored and which is the repository itself.

On a client you typically have both the repository and the working folder. A command like "checkout" pulls things out of the repository and copies them to the working folder. Commands like "add" and "commit" take files from the working folder and save them to the repository.

Well, a "remote" repository that you want to push must only consist of the repository and not the working folder. For this, this repository must be created with:

$ git --bare init

The logic of this is that perhaps the repository you are push has an owner who is also working and who may not be amused that their working copy is suddenly changed by a push that you have done. So to ensure that this does not happen, he forces the working copy is nonexistent and only be a repository "naked" (bare).

So, answering your questions:

Why do I have to use receive.denyCurrentBranch ignore in server repository?

Because, as it is not created as bare , it will reject any push attempt, unless you configure it to tell it what to do when faced with those attempts.

Once you have done it, the files in the / home / alberto / git / app directory are not created on the server. Why are they not created?

Because the ignore option that you have set indicates precisely that, to save the changes in the repository but not to update the working copy (you could update it manually by executing git checkout master in the server folder).

Recent versions of git support this configuration option on a "non-bare" server:

$ git config receive.denyCurrentBranch updateInstead

This option causes it to update your working copy when someone changes the repository via push . But be careful with this option, since as I explained before, the original behavior of git to prevent these push had a reason for being and with this option we are skipping it.

Scroll to Top