Created
October 4, 2016 21:08
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# 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