Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script for automatically creating a bare git repo in Dropbox (for tracking pre-existing private repo)
##
# This script adds a new git repo to Dropbox (named after the current working
# directory), adds it as a remote, and pushes everything to it. If there is an
# argument, then that will be used as the name of the repo instead of the
# current working directory.
#
# EXAMPLE USAGE:
#
# $ cd existing-repo
# $ /path/to/dropbox-git-init.sh
# => $dropboxReposDir/existing-repo.git
#
# $ cd existing-repo
# $ /path/to/dropbox-git-init.sh other-name
# => $dropboxReposDir/other-name.git
##
# CUSTOMIZE THIS PATH! Needs to point to an existing path in Dropbox
dropboxReposDir="$HOME/Dropbox/Code/repos"
# Grab our base directory name (or first argument) and active branch
curDir=$PWD
baseDir=${PWD##*/}
if [ ! -z "$1" ]
then
baseDir=$1
fi
curBranch=`git rev-parse --abbrev-ref HEAD`
# Move into our root Dropbox repos folder
cd "$dropboxReposDir"
mkdir "${baseDir}.git"
cd "${baseDir}.git"
git --bare init
# Move back to our original project
cd "$curDir"
git remote add dropbox "file://${dropboxReposDir}/${baseDir}.git"
git push -u dropbox "$curBranch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.