See manual at: https://github.com/git-ftp/git-ftp/blob/master/man/git-ftp.1.md
Install git-ftp package: https://github.com/git-ftp/git-ftp/blob/master/INSTALL.md
curl https://raw.githubusercontent.com/git-ftp/git-ftp/master/git-ftp > /bin/git-ftp
chmod 755 /bin/git-ftp
Move to your local project root. Example setup for scope named productive
# FTP
git config git-ftp.productive.url ftp://ftpserver123.com:21/path/to/your/project
git config git-ftp.productive.user johndoe
git config git-ftp.productive.password s3cr3t
# SFTP with SSH key
git config git-ftp.productive.url sftp://ftpserver123.com:22/path/to/your/project
git config git-ftp.productive.user johndoe
git config git-ftp.productive.key ~/.ssh/id_rsa
git ftp init -s <scope-name> # First usage
git ftp push -s <scope-name> # Normal usage
git-ftp cannot ask you for a passphrase for your private key. You can store the passphrase in your ssh-agent as a workaround:
ssh-agent bash
ssh-add ~/.ssh/<YOUR_KEY_NAME>
git-ftp supports hooks, that means scripts that are automatically called before or after pushing code with git-ftp.
I wrote a post-ftp-push
hook to set git tags corresponding to the pushed scope.
E.g. pushing a specific commit to testing scope will set a test-system
tag on the pushed commit.
Create a text file called (it has no extension) .git/hooks/post-ftp-push
#!/bin/bash
remote="$1"
url="$2"
local_sha="$3"
remote_sha="$4"
case $remote in
"test")
tag="test-system"
;;
"productive")
tag="productive"
;;
*)
echo "[POST PUSH ($remote)] WARNING: Unknown git-ftp scope '$remote'. Using scope name as tag name"
tag=$remote
;;
esac;
echo "-----------------"
echo "Updating files for the following commits:"
git log --pretty=format:%s $tag..HEAD
echo "-----------------"
echo "Handling deployment tags"
git tag -d "$tag"
git tag "$tag"
echo "[POST PUSH ($remote)] Removed tag '$tag' from old commits."
echo "[POST PUSH ($remote)] Added tag '$tag' to current commit $local_sha."
exit 0
Adding this pre-ftp-push
hook to git's hooks folder allways writes the current commit id to a file called .version
.
#!/bin/bash
local_sha="$3"
echo "Updating version hash in .version file"
echo -n "$local_sha" > .version
exit 0
Adding this line to the .git-ftp-include
file, allways uploads the .version
file to the remote server
.git-ftp-include
Hint: It might be usefull to add the
.version
file to your.gitignore
file