Skip to content

Instantly share code, notes, and snippets.

@lanmaster53
Last active December 7, 2018 15:02
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 lanmaster53/a2a686328fe859ab8d666dcdea5659a1 to your computer and use it in GitHub Desktop.
Save lanmaster53/a2a686328fe859ab8d666dcdea5659a1 to your computer and use it in GitHub Desktop.
Basic script to update git repository without any history or excess data in .git
#!/bin/bash
# Basic script to update a git repository without any history or excess data in .git.
# Parses the url from .git/config, downloads latest version, and purges everything in .git/ except the config file.
# Limitations:
# * Only works with the master branch.
# * Doesn't account for local virtual environments.
# * Doesn't allow for maintaining a stash of changes.
if [ -f $FILE ]; then
# parse the url from the config file
url=`grep -e 'url = ' .git/config | sed 's/.*url = //'`
# remove all files from the current directory
rm -rf ..?* .[!.]* *
# clone the parsed url into the currect directory
git clone --depth 1 $url ./
# clean up the .git directory
cd .git
find . ! -name 'config' -exec rm -rf {} + 2> /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment