Skip to content

Instantly share code, notes, and snippets.

@briceburg
Last active October 12, 2019 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briceburg/d23ade62293b1ad075edeb158775f9e1 to your computer and use it in GitHub Desktop.
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
#!/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