Deploy Website Through Git

I am working on a website development team. Each of us has a personal website created in our home directories on the development server.

We want to convert them to git production repositories so that we can branch, reinstall, and usually take advantage of git kindness.

When reading online, there are several options:

1) create a bare repo that synchronizes with the working repo in www / through the hook after receiving.

2) click directly on the working repo

The problem with option 1 is that it cannot handle branching. When we click on a branch other than the master, the hook after reception still only synchronizes the master, so our changes never appear on the development site.

Issue with option 2 - git prohibits clicking on the extracted branch to prevent the detached HEAD state.

When reading online, the โ€œbest practiceโ€ solution for option 2 looks something like this:

1) when CLIENT is pressed on a dummy branch

2) on SERVER, the fiction in master is merged ... BUZZZZ the wrong answer. Assume that end users do not have access to the server on the server.

So, I thought: โ€œNo problem, just create an email reception like thisโ€:

#!/bin/bash read oldSHA newSHA branch git merge $branch 

Now here's the weird part: when the post-hook is executed, I get

 Please, commit your changes or stash them before you can merge. 

Yes, I confirmed that the wizard is a marked branch on the server, and that the dummy branch has been updated correctly. When I run the same command (git merge dummy) directly on the server, everything works fine.

Can someone explain why?

Thanks in advance.

EDIT 1

Below are the git state results of both pre-merge and post-merge

 Counting objects: 5, done. Delta compression using up to 8 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 307 bytes, done. Total 3 (delta 2), reused 0 (delta 0) remote: **** PRE MERGE **** remote: # On branch master remote: # Untracked files: remote: # (use "git add <file>..." to include in what will be committed) remote: # remote: # COMMIT_EDITMSG remote: # FETCH_HEAD remote: # HEAD remote: # ORIG_HEAD remote: # config remote: # description remote: # hooks/ remote: # index remote: # info/ remote: # logs/ remote: # objects/ remote: # packed-refs remote: # refs/ remote: no changes added to commit (use "git add" and/or "git commit -a") remote: error: Your local changes to the following files would be overwritten by merge: remote: index.htm remote: Please, commit your changes or stash them before you can merge. remote: Aborting remote: **** POST MERGE **** remote: # On branch master remote: # Changes not staged for commit: remote: # (use "git add <file>..." to update what will be committed) remote: # (use "git checkout -- <file>..." to discard changes in working directory) remote: # remote: # modified: index.htm remote: # remote: # Untracked files: remote: # (use "git add <file>..." to include in what will be committed) remote: # remote: # COMMIT_EDITMSG remote: # FETCH_HEAD remote: # HEAD remote: # ORIG_HEAD remote: # config remote: # description remote: # hooks/ remote: # index remote: # info/ remote: # logs/ remote: # objects/ remote: # packed-refs remote: # refs/ remote: no changes added to commit (use "git add" and/or "git commit -a") 

Please note that I can do manual git add., Git commit -m "foo" and re-execute this process with the same result

+4
source share
1 answer

In one of these "DUH!" moments, I realized that I could use option 1 and just pass the name of the branch as I tried with option 2.

So, I created a /home/username/www.git bare repository, cloned it to / home / username / www and added a post-receive hook to /home/username/www.git, which looks something like this:

 #!/bin/bash read oldSHA newSHA branch git --git-dir="/home/username/www/.git" --work-tree="/home/username/www" pull /home/username/www.git $branch 

Then I changed my remote to ssh: // username@example.com /home/username/www.git (naked reop, not working) and clicked on this remote via:

 git push remoteName branchName 

Voila! Everything works.

The actual code after reception is more complicated, since I use some traps and error variables for directory names (therefore, they can be deployed for any user), but you get the idea.

(Be careful to distinguish between www / .git and www.git when reading code samples.)

+2
source

Source: https://habr.com/ru/post/1479806/


All Articles