Last active
October 12, 2019 02:24
-
-
Save briceburg/d23ade62293b1ad075edeb158775f9e1 to your computer and use it in GitHub Desktop.
git-scp: sync the working copy with a remote host, respecting the .gitignores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# git-scp: sync the working copy with a remote host, respecting the .gitignores | |
# usage: git scp devbox | |
# where 'devbox' refers to a tracked remote. e.g. | |
# git remote add devbox host:~/git/repo-name | |
# | |
# installation: cp git-scp /usr/local/bin/git-scp && chmod +x /usr/local/bin/git-scp | |
# | |
set -eo pipefail | |
main(){ | |
remote="$1" | |
[ -n "$remote" ] || die "[ERR] provide a remote name as first argument" | |
git config remote.$remote.url &>/dev/null || die \ | |
"[ERR] missing remote: $remote" \ | |
"example: git remote add $remote host:~/git/repo-name" | |
cd "$(git rev-parse --show-toplevel)" | |
find . -path ./.git -prune -o -print \ | |
| git check-ignore --verbose --non-matching --stdin \ | |
| sed -n -e 's,^::[[:space:]]*,,p' | \ | |
rsync -av --files-from=- . "$(git config remote.$remote.url)/" | |
} | |
log(){ echo -e "$*" >&2; } | |
die(){ log "$*"; exit 1; } | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment