Merge branch 'develop' into feature/Issue50
diff --git a/AUTHORS b/AUTHORS
index d4e7490..1c29754 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -16,5 +16,7 @@
 - Kiall Mac Innes
 - Jon Bernard
 - Olivier Mengué
+- Emre Berge Ergenekon
+- Eric Holmes
 
 Portions derived from other open source works are clearly marked.
diff --git a/Changes.mdown b/Changes.mdown
index 53858b6..4e39369 100644
--- a/Changes.mdown
+++ b/Changes.mdown
@@ -2,11 +2,16 @@
 -----
 Release date: **not yet**
 
+* `git flow init` now detects situations where origin already has gitflow
+  branches set up, and behaves accordingly (thanks Emre Berge Ergenekon)
+
 * `git flow feature finish` can now be called without a feature branch
   name(prefix) argument and will finish the current branch, if on any.
 
 * Various minor bug fixes related to internal argument passing
 
+* Better support for Windows users.
+
 * Add package installers for the Debian and Windows platforms.
 
 0.4.1:
diff --git a/README.mdown b/README.mdown
index b3e1df3..70d944d 100644
--- a/README.mdown
+++ b/README.mdown
@@ -14,77 +14,14 @@
 
 Or have a look at one of these screen casts:
 
+* [How to use a scalable Git branching model called git-flow](http://buildamodule.com/video/change-management-and-version-control-deploying-releases-features-and-fixes-with-git-how-to-use-a-scalable-git-branching-model-called-gitflow) (by Build a Module)
 * [A short introduction to git-flow](http://vimeo.com/16018419) (by Mark Derricutt)
 * [On the path with git-flow](http://codesherpas.com/screencasts/on_the_path_gitflow.mov) (by Dave Bock)
 
 
 Installing git-flow
 -------------------
-
-### Mac OS
-If you're on a Mac and use [homebrew](http://github.com/mxcl/homebrew), it's simple:
-
-    $ brew install git-flow
-
-If you're on a Mac and use [MacPorts](http://macports.org/), it's simple:
-
-    $ port install git-flow
-
-### Linux, etc.
-Another easy way to install git-flow is using Rick Osborne's excellent git-flow
-installer, which can be run using the following command:
-
-	$ wget --no-check-certificate -q -O - https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | sudo bash
-
-### Windows
-
-For Windows users, [msysgit](http://code.google.com/p/msysgit/) is a good
-starting place for installing git.
-
-#### Using Cygwin
-For Windows users who wish to use the automated install, it is suggested that you install [Cygwin](http://www.cygwin.com/)
-first to install tools like `git`, `util-linux` and `wget` (with those three being packages that can be selected
-during installation). Then simply run this command from a Cygwin shell:
-
-	$ wget -q -O - https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | bash
-
-#### Using [msysgit](http://code.google.com/p/msysgit/)
-Download and install `getopt.exe` from the [util-linux package](http://gnuwin32.sourceforge.net/packages/util-linux-ng.htm) into `C:\Program Files\Git\bin`. (Only `getopt.exe`, the others util-linux files are not used). Also install `libintl3.dll` from the Dependencies package, into the same directory. 
-
-Clone the git-flow sources from GitHub:
-
-	$ git clone --recursive git://github.com/nvie/gitflow.git
-	$ cd gitflow
-
-Run the `msysgit-install` script from a command-line prompt (you may have to
-run it with "Full Administrator" rights if you installed msysgit with its
-installer):
-
-	C:\gitflow> contrib\msysgit-install.cmd
-
-### Manual installation
-If you prefer a manual installation, please use the following instructions:
-
-	$ git clone --recursive git://github.com/nvie/gitflow.git
-
-Then, you can install `git-flow`, using:
-
-	$ sudo make install
-
-By default, git-flow will be installed in /usr/local. To change the prefix
-where git-flow will be installed, simply specify it explicitly, using:
-
-	$ sudo make prefix=/opt/local install
-
-Or simply point your `PATH` environment variable to your git-flow checkout
-directory.
-
-*Installation note:*  
-git-flow depends on the availability of the command line utility `getopt`,
-which may not be available in your Unix/Linux environment.  Please use your
-favorite package manager to install `getopt`.  For Cygwin, install the
-`util-linux` package to get `getopt`.  If you use `apt-get` as your install
-manager, the package name is `opt`.
+See the Wiki for up-to-date [Installation Instructions](https://github.com/nvie/gitflow/wiki/Installation).
 
 
 Integration with your shell
@@ -115,6 +52,23 @@
 Any questions, tips, or general discussion can be posted to our Google group:
 [http://groups.google.com/group/gitflow-users](http://groups.google.com/group/gitflow-users)
 
+Contributing
+------------
+Fork the repository.  Then, run:
+
+    git clone --recursive git@github.com:<username>/gitflow.git
+    cd gitflow
+    git branch master origin/master
+    git flow init -d
+    git flow feature start <your feature>
+
+Then, do work and commit your changes.  **Hint**: ``export PATH=`pwd`:$PATH``
+from within the gitflow directory makes sure you're using the version of
+gitflow you're currently developing.
+
+    git flow feature publish <your feature>
+
+When done, open a pull request to your feature branch.
 
 License terms
 -------------
diff --git a/contrib/msysgit-install.cmd b/contrib/msysgit-install.cmd
index 1285839..5f005bf 100644
--- a/contrib/msysgit-install.cmd
+++ b/contrib/msysgit-install.cmd
@@ -22,11 +22,11 @@
 

 if not exist "%GIT_HOME%\bin\git-flow" goto :Install

 echo GitFlow is already installed.>&2

-choice /C YN /M "Do you want to replace it"

-if errorlevel 255 goto :Abort

-if errorlevel 2 goto :Abort

-if not errorlevel 1 goto :Abort

+set /p mychoice="Do you want to replace it [y/n]"

+if "%mychoice%"=="y" goto :DeleteOldFiles

+goto :Abort

 

+:DeleteOldFiles

 echo Deleting old files...

 for /F %%i in ("%GIT_HOME%\git-flow*" "%GIT_HOME%\gitflow-*") do if exist "%%~fi" del /F /Q "%%~fi"

 

diff --git a/git-flow b/git-flow
index 97b1b34..a03ba1f 100755
--- a/git-flow
+++ b/git-flow
@@ -42,7 +42,9 @@
 	set -x
 fi
 
-export GITFLOW_DIR=$(dirname "$0")
+# The sed expression here replaces all backslashes by forward slashes.
+# This helps our Windows users, while not bothering our Unix users.
+export GITFLOW_DIR=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
 
 usage() {
 	echo "usage: git flow <subcommand>"
diff --git a/git-flow-feature b/git-flow-feature
index 9da4b0b..726b4ae 100644
--- a/git-flow-feature
+++ b/git-flow-feature
@@ -44,7 +44,7 @@
 usage() {
 	echo "usage: git flow feature [list] [-v]"
 	echo "       git flow feature start [-F] <name> [<base>]"
-	echo "       git flow feature finish [-rFk] [<name|nameprefix>]"
+	echo "       git flow feature finish [-rFkD] [<name|nameprefix>]"
 	echo "       git flow feature publish <name>"
 	echo "       git flow feature track <name>"
 	echo "       git flow feature diff [<name|nameprefix>]"
@@ -231,6 +231,7 @@
 	DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
 	DEFINE_boolean rebase false "rebase instead of merge" r
 	DEFINE_boolean keep false "keep branch after performing finish" k
+	DEFINE_boolean force_delete false "force delete feature branch after finish" D
 	parse_args "$@"
 	expand_nameprefix_arg_or_current
 
@@ -346,7 +347,11 @@
 	
 	
 	if noflag keep; then
-		git branch -d "$BRANCH"
+		if flag force_delete; then
+			git branch -D "$BRANCH"
+		else
+			git branch -d "$BRANCH"
+		fi
 	fi
 
 	echo
diff --git a/git-flow-hotfix b/git-flow-hotfix
index 5c07907..b355f30 100644
--- a/git-flow-hotfix
+++ b/git-flow-hotfix
@@ -46,6 +46,7 @@
 	echo "usage: git flow hotfix [list] [-v]"
 	echo "       git flow hotfix start [-F] <version> [<base>]"
 	echo "       git flow hotfix finish [-Fsumpk] <version>"
+	echo "       git flow hotfix publish <version>"
 }
 
 cmd_default() {
@@ -188,6 +189,33 @@
 	echo
 }
 
+cmd_publish() {
+	parse_args "$@"
+	require_version_arg
+
+	# sanity checks
+	require_clean_working_tree
+	require_branch "$BRANCH"
+	git fetch -q "$ORIGIN"
+	require_branch_absent "$ORIGIN/$BRANCH"
+
+	# create remote branch
+	git push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH"
+	git fetch -q "$ORIGIN"
+
+	# configure remote tracking
+	git config "branch.$BRANCH.remote" "$ORIGIN"
+	git config "branch.$BRANCH.merge" "refs/heads/$BRANCH"
+	git checkout "$BRANCH"
+
+	echo
+	echo "Summary of actions:"
+	echo "- A new remote branch '$BRANCH' was created"
+	echo "- The local branch '$BRANCH' was configured to track the remote branch"
+	echo "- You are now on branch '$BRANCH'"
+	echo
+}
+
 cmd_finish() {
 	DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
 	DEFINE_boolean sign false "sign the release tag cryptographically" s
diff --git a/git-flow-init b/git-flow-init
index 57ab244..4afa1c2 100644
--- a/git-flow-init
+++ b/git-flow-init
@@ -117,8 +117,14 @@
 
 		# check existence in case of an already existing repo
 		if [ "$should_check_existence" = "YES" ]; then
-			git_local_branch_exists "$master_branch" || \
+			# if no local branch exists and a remote branch of the same
+			# name exists, checkout that branch and use it for master
+			if ! git_local_branch_exists "$master_branch" && \
+				git_remote_branch_exists "origin/$master_branch"; then
+				git branch "$master_branch" "origin/$master_branch" >/dev/null 2>&1
+			elif ! git_local_branch_exists "$master_branch"; then
 				die "Local branch '$master_branch' does not exist."
+			fi
 		fi
 
 		# store the name of the master branch
@@ -200,7 +206,11 @@
 	# default production branch and develop was "created".  We should create
 	# the develop branch now in that case (we base it on master, of course)
 	if ! git_local_branch_exists "$develop_branch"; then
-		git branch --no-track "$develop_branch" "$master_branch"
+		if git_remote_branch_exists "origin/$develop_branch"; then
+			git branch "$develop_branch" "origin/$develop_branch" >/dev/null 2>&1
+		else
+			git branch --no-track "$develop_branch" "$master_branch"
+		fi
 		created_gitflow_branch=1
 	fi
 
diff --git a/gitflow-common b/gitflow-common
index 252f5d0..fb515de 100644
--- a/gitflow-common
+++ b/gitflow-common
@@ -97,6 +97,10 @@
 	has $1 $(git_local_branches)
 }
 
+git_remote_branch_exists() {
+	has $1 $(git_remote_branches)
+}
+
 git_branch_exists() {
 	has $1 $(git_all_branches)
 }