Skip to content

Instantly share code, notes, and snippets.

@ylem
Last active January 29, 2023 22:09
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
#server side:
#server live directory: /var/www/domain.com
#server repository: /var/repo/site.git
1. clone project from git/bitbucket into /var/www/domain.com or init the folder by "git init".
2. go to /var/repo/site.git and init the folder as git bare
$git init --bare
--bare means that our folder will have no source files, just the version control.
3. still in site.git folder go to hooks.
$cd hooks
$cat > post-receive # When you execute this command, you will have a blank line indicating that everything you type will be saved to this file
type:
#!/bin/sh
git --work-tree=/var/www/domain.com --git-dir=/var/repo/site.git checkout -f
4. $chmod +x post-receive
$exit
#Local workspace:
1. go to your "git" project folder.
2. $git remote add live ssh://user@mydomain.com/var/repo/site.git
3. after any changes. remrember "push" to both live and master
$git push
then
$git push live
@medmek
Copy link

medmek commented Aug 8, 2020

Thanks for this ! When I saw "automatic" int the title, I thought it will be done without having to explicitly do this :

then
$git push live

Cuz I'm searching for a way to automaticly cause a git pull from the server side when my github repo is updated (either from workspace or from github web interface)

@ylem
Copy link
Author

ylem commented Aug 10, 2020

Hi @medmek,

Not sure what you want to do, but as I understand. The local process (when you have any updates), you just need to push to remote
$git push live

Then your server side will pull the latest updates automatically. ( live is a short name of ssh://user@mydomain.com/var/repo/site.git)

@kelsin
Copy link

kelsin commented Jan 29, 2023

Thanks for this ! When I saw "automatic" int the title, I thought it will be done without having to explicitly do this :

then
$git push live

Cuz I'm searching for a way to automaticly cause a git pull from the server side when my github repo is updated (either from workspace or from github web interface)

This solution doesn't help with that. If you want to do that you either need a server or process living somewhere that can respond to webhooks that github can send on PR/Commits or you setup github actions or other CI actions from another CI tool that will do the deploy steps. This process is for having a git repo that lives on the server that deploys after a push to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment