I search the method to copy files to "test" host when I launch the "git push" command.
git push ------- TO REPO --> REPO_SERVER
\
\_________ TO DIR --> Host_TEST
Git Version: 2.20.1
I search the method to copy files to "test" host when I launch the "git push" command.
git push ------- TO REPO --> REPO_SERVER
\
\_________ TO DIR --> Host_TEST
Git Version: 2.20.1
It sounds like you are trying to (re) invent CI/CD.
If you are using GitHub or GitLab as a remote server you can use Pipelines
(or Actions
in GitHub).
In there you can define (almost) anything you want to happen after a push, I am assuming your Host_TEST
is accessible online.
In case you are running your own git server
You can implement "push to deploy" using the post-receive
hook. Hooks are scripts that are placed inside .git/hooks
and executed at a precise phase of a git command. you can find several example implementations in .git/hook
. See here for more information: Setting up Push-to-Deploy with git
In case you don't have access to your own git server
You can use the pre-push
script on your local machine, BUT THIS IS A BAD IDEA
This hooks is executed after you execute git push
but before git
actually pushes anything. If your script fails (i.e non-zero return code) it will not push.
Also, if your script manages to copy but then git
fails to push you will end up testing code that's not in your repo.
If all this sound way too complicated
You can create a bash function that does both operations and add it to your .bashrc
.
Here is an example:
push_copy() {
if git push
then
# Copy for command here: scp ...
else
echo "Failed..."
fi
}