Skip to content

Instantly share code, notes, and snippets.

@tbnorth
Created March 1, 2021 17:27
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 tbnorth/45d6395e1bd3de3280b952519a937c33 to your computer and use it in GitHub Desktop.
Save tbnorth/45d6395e1bd3de3280b952519a937c33 to your computer and use it in GitHub Desktop.
git repo based file transfer
#!/bin/bash
# gtp put branch files
# gtp list
# gtp get # last branch
# gtp get branch
REPO=$HOME/gtp_repo
to_branch_name () {
# use UTC because cross timezone transfers will be a common use case
echo "$(date -u +%Y%m%d%H%M%S) $@" | sed -r 's/^\s+//; s/\s+$//; s/ /_/g'
}
get_branches () {
cd $REPO && git fetch && git branch -r | sed 's%^\s\+origin/%%' | sort -r | grep -v HEAD
}
put () {
BRANCH=$(to_branch_name $1)
shift
(rm -rf $REPO/file_set && mkdir $REPO/file_set)
cp -r $@ $REPO/file_set/
(cd $REPO/file_set && git checkout --orphan ${BRANCH} &&
git add -A . && git commit -am'added files' &&
git push -u origin ${BRANCH}
)
}
get () {
if [ "$1" ]; then
BRANCH="$1"
else
BRANCH=$(get_branches | head -1)
fi
(cd $REPO && git checkout ${BRANCH})
cp -rv $REPO/file_set/* .
}
list () {
for BRANCH in $(get_branches); do
echo $BRANCH
(cd $REPO && git log --name-only --oneline origin/$BRANCH |
tail -n +2 | sed 's%^file_set/% %' )
done | less -E
}
CMD="$1"
shift
$CMD "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment