For controlled delivery/deployment of your project to custom remote git repositories.
Replace %%repo-name%% with your custom name for the remote bare repo you are creating. I prefer using /var/git as the recipient folder but this can be any folder for witch the user has read/write access.
On the remote/recipient server
Create and navigate to the target folder
cd /var/git
Create a new bare repo with the desired name
git init %%repo-name%%.git --bare
Navigate to the hooks folder of the new repo folder
cd %%repo-name%%.git/hooks
Copy the post-update.sample into a new file called simply post-update
cp post-update.sample post-update
Open the post-update file for editing
nano post-update
Replace the contents with the following bash script. /var/www/ needs to be replaced with your preferred web-root or public folder. "master" branch can be renamed onto any other branch you want the bash script to use when the bare repo detects new updates.
#!/bin/sh
cd /var/www/%%repo-name%% || exit
unset GIT_DIR
git pull hub master
exec git update-server-info
Save the edits and exit.
Clone the bare repo into the folder referenced in the bash script
git clone /var/git/%%repo-name%%.git /var/www/%%repo-name%%
Navigate to the folder referenced in the bash script
cd /var/www/%%repo-name%%
Rename the default "origin" reference to "hub"
git remote rename origin hub
Add the new repo as a remote in your local git repository.
The user included in the new remote path has to have read/write access over SSH to the bare repo folder as well as the target web-root/public folder on the remote server.
git remote add stage [email protected]:/var/git/%%repo-name%%.git
"stage" can be renamed to any name you want to use to separate this remote from the others (like origin) in the git repo.
Finally, fetch the new remote into your local git repo.
git fetch stage