Skip to content

Instantly share code, notes, and snippets.

@quickshiftin
Forked from subtleGradient/git-transmit
Last active January 1, 2020 16:00
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quickshiftin/8809435 to your computer and use it in GitHub Desktop.
Save quickshiftin/8809435 to your computer and use it in GitHub Desktop.
Checkout this approach for knowing what to transfer. This revision uses a local tag to track each time you use the command. The first time you use it, it pushes all files in the project. At the end of each run it updates the tag to point to HEAD. Next time you run it, it will only push files that have changed since the last push.
#!/usr/bin/env bash
# author: Thomas Aylott SubtleGradient.com
# author: Nathan Nobbe quickshiftin.com
# Find out where HEAD is pointing
head_ref=$(git show-ref --head -s | head -n 1)
# Check to see if transmit tag exists, and get transmit tag hash
_transmit_ref=$(git show-ref --verify -s refs/tags/transmit)
# If there's not transmit tag, create it for the first time.
if [ $? -gt 0 ]; then
# This won't work well for projects with multiple roots,
# but for the typical case it will find the first commit
# and tag that for the initial push.
first_commit=$(git rev-list --max-parents=0 HEAD)
echo 'Creating initial transmit tag'
git tag -m 'Creating transmit tag' transmit $first_commit
fi
# Find out where the tag is pointing
# @note Probably a cleaner way to do this ...
transmit_ref=$(git cat-file tag $_transmit_ref | head -n 1 | sed 's/^object //')
# If the transmit tag is the same commit as HEAD,
# there's nothing to do
if [ "$transmit_ref" == "$head_ref" ]; then
echo 'No changes to push'
exit 0
fi
# Iterate over all the files that changed, adding then to Transmit
echo 'Transmitting'
for i in $(git diff --name-only transmit HEAD); do
if [[ -e "$i" ]]; then
echo "Adding $i to Transmit"
open -a Transmit "$i"
fi
done
# Update the tag so we know where the last push occurred
echo 'Updating transmit tag'
git tag -d transmit
git tag -m 'Updating transmit tag' transmit HEAD
@jannejava
Copy link

Can I in someway specify a commit for upload? Usually have to a site already up and running and I would rather not upload it again, only my minor changes.

@quickshiftin
Copy link
Author

@jannejava That's the whole idea behind this script. It will only push what has changed since the last time you pushed.

@reibejoy
Copy link

On OSX 10.11.2 this is what I get, trying to copy the file to /usr/sbin/ (btw: there's a typo in your cp line @quickshiftin)

sudo cp git-transmit /usr/sbin/ 
cp: /usr/sbin/git-transmit: Operation not permitted 

@quickshiftin
Copy link
Author

quickshiftin commented Nov 14, 2017

Hi @reibejoy. It looks like need to use sudo.

@pinoceniccola
Copy link

Same problem as @reibejoy, solved using /usr/local/sbin/ instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment