available:

  • server with git and ssh access
  • On the server in the directory /путь/к/ ordinary (non-bare) git storage was created using the git init command.
  • the user on whose behalf I am connecting has rights to write to this directory

required:

  • so that when sending changes with the git push command to any branch from the local clone of this repository, the updated files immediately appear on the server in the working directory /путь/к/ exactly as they appear in this very branch

Yes, I know about the pitfalls . measures taken.

How to configure the storage on the server so that it works exactly as I need?

    1 answer 1

    on server:

    1. in the directory /путь/к/ execute the command:

       $ git config receive.denyCurrentBranch ignore 
    2. in the repository ( /путь/к/.git/ ) create a file /путь/к/.git/hooks/post-update following content:

       #!/bin/sh GIT_WORK_TREE=$(dirname $PWD) git reset --hard $(git rev-parse $1) 
    3. add the executable bits to this file:

       $ chmod +x /путь/к/.git/hooks/post-update 

    everything.

    Now you can clone this repository yourself locally:

     $ git clone пользователь@сервер:/путь/к/ 

    add files, branches, commit and send changes to the server with the git push command (it is clear that if there are no branches on the server yet, you will need to specify it, for example: git push origin ветка ).


    if you suddenly need to switch to another commit / branch without creating a new commit, you will have to manually execute git checkout -f ... in the directory /путь/к/ ) or git reset --hard ...


    inspired by these questions (and answers to them) with one goal - to simplify the process: