Here's a script that I wrote to do just this thing. The script handles all my usual initialization of new git repos
- creates .gitignore file
- initializes .git
- creates the bare git repo on the server
- sets up the local git repo to push to that remote repo
You'll definitely have to modify it to suit whatever setup you've got, especially if you're dealing with Windows laptop/desktop.
Here is the full script:
#!/bin/bash# Create Git Repository# created by Jim Kubicek, 2009# jimkubicek@gmail.com# http://jimkubicek.com# DESCRIPTION# Create remote git repository from existing project# this script needs to be run from within the project directory# This script has been created on OS X, so YMMV######## ParametersREPLOGIN=#Login nameREPADDRESS=#Repo addressREPLOCATION=/Users/Shared/Development #Repo location# The repo name defaults to the name of the current directory.# This regex will accept foldernames with letters and a period.# You'll have to edit it if you've got anything else in your folder names.REPNAME=`pwd | egrep -o "/[a-zA-Z]+$" | egrep -o "[a-zA-Z\.]+"`# If you have standard files/directories to be ignored# add them hereecho "Creating .gitignore"echo 'build/'>> .gitignore # The build directory should be ignored for Xcode projsecho '.DS_Store'>> .gitignore # A good idea on OS X# Create the git repoecho "Initializing the repo"git initgit add .git commit -m "Initial commit"# Copy the repo to the serverecho "Copying the git repo to the server $REPADDRESS"TEMPREP="$REPNAME.git"git clone --bare .git $TEMPREPscp -r $TEMPREP $REPLOGIN@$REPADDRESS:$REPLOCATION/rm -rf $TEMPREP# Set up the origin for the projectecho "Linking current repository to remote repository"git remote add origin $REPLOGIN@$REPADDRESS:$REPLOCATION/$REPNAME.git/