Skip to content

Instantly share code, notes, and snippets.

@onecrayon
Created October 4, 2016 21:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onecrayon/0184a28bdb892c81f96653630941acad to your computer and use it in GitHub Desktop.
Save onecrayon/0184a28bdb892c81f96653630941acad to your computer and use it in GitHub Desktop.
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