Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ EXEC_FILES=git-flow

# files that need mode 644
SCRIPT_FILES =git-flow-init
SCRIPT_FILES+=git-flow-clone
SCRIPT_FILES+=git-flow-feature
SCRIPT_FILES+=git-flow-hotfix
SCRIPT_FILES+=git-flow-release
Expand Down
4 changes: 4 additions & 0 deletions README.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ you would like to use as development and production branches, and how you
would like your prefixes be named. You may simply press Return on any of
those questions to accept the (sane) default suggestions.

Alternatively, you can clone an existing repo that utilizes git flow:

git flow clone <repository>


### Creating feature/release/hotfix/support branches

Expand Down
3 changes: 2 additions & 1 deletion git-flow
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ usage() {
echo
echo "Available subcommands are:"
echo " init Initialize a new git repo with support for the branching model."
echo " clone Clone an existing git repo that uses git flow."
echo " feature Manage your feature branches."
echo " release Manage your release branches."
echo " hotfix Manage your hotfix branches."
Expand Down Expand Up @@ -94,7 +95,7 @@ main() {
# in that case, we interpret this arg as a flag for the default
# command
SUBACTION="default"
if [ "$1" != "" ] && { ! echo "$1" | grep -q "^-"; } then
if [ "$1" != "" ] && [ ! "$NO_SUBACTION" ] && { ! echo "$1" | grep -q "^-"; } then
SUBACTION="$1"; shift
fi
if ! type "cmd_$SUBACTION" >/dev/null 2>&1; then
Expand Down
137 changes: 137 additions & 0 deletions git-flow-clone
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#
# git-flow -- A collection of Git extensions to provide high-level
# repository operations for Vincent Driessen's branching model.
#
# Original blog post presenting this model is found at:
# http://nvie.com/git-model
#
# Feel free to contribute to this project at:
# http://github.com/nvie/gitflow
#
# Copyright 2010 Vincent Driessen. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of Vincent Driessen.
#

NO_SUBACTION=true

usage() {
echo "usage: git flow clone <repository> [-d]"
}

parse_args() {
# parse options
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"

REPO=$1
DIRECTORY=`echo "$REPO" | sed "s/.*[/:]//g" | sed "s/\.git//g"`
}

# Default entry when no SUBACTION is given
cmd_default() {
cmd_clone "$@"
}

# Clone an existing repository that already uses git flow
cmd_clone() {
DEFINE_boolean defaults false 'use default branch naming conventions' d
parse_args "$@"
ORIGIN="origin"

if [ "$REPO" == "" ]; then
usage
exit 1
fi

mkdir "$DIRECTORY" || die "git flow clone aborted. Could not create directory $DIRECTORY"
cd "$DIRECTORY"

git init > /dev/null 2>&1
require_git_repo

git remote add "$ORIGIN" "$REPO"
git fetch

# Fetch failed, so it's probably not a git repository
if [ "$?" -ne "0" ]; then
cd ..
rm -r "$DIRECTORY"
exit 1
fi

if flag defaults; then
git flow init -d
else
git flow init
fi

require_gitflow_initialized
gitflow_load_settings

tracking_master=false
tracking_develop=false

# Track the remote master branch if it exists
if git_remote_branch_exists "$ORIGIN/$MASTER_BRANCH"; then
git branch -D "$MASTER_BRANCH" > /dev/null 2>&1
git checkout -b "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
tracking_master=true
fi

# Track the remote develop branch if it exists
if git_remote_branch_exists "$ORIGIN/$DEVELOP_BRANCH"; then
git branch -D "$DEVELOP_BRANCH" > /dev/null 2>&1
git checkout -b "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
tracking_develop=true

# Create the develop branch if the remote develop branch doesn't exist
elif "$tracking_master"; then
git branch -D "$DEVELOP_BRANCH" > /dev/null 2>&1
git checkout -b "$DEVELOP_BRANCH" "$MASTER_BRANCH"
fi

# Switch to the develop branch
git checkout "$DEVELOP_BRANCH"

echo
echo "Summary of actions:"
echo "- Repository $REPO was cloned"
if "$tracking_master"; then
echo "- The local branch $MASTER_BRANCH was configured to track the remote branch"
else
echo "- The local branch $MASTER_BRANCH was created"
fi
if "$tracking_develop"; then
echo "- The local branch $DEVELOP_BRANCH was configured to track the remote branch"
elif "$tracking_master"; then
echo "- The local branch $DEVELOP_BRANCH was created based on the $MASTER_BRANCH branch"
else
echo "- The local branch $DEVELOP_BRANCH was created"
fi
echo "- You are on the $DEVELOP_BRANCH branch"
echo
}
4 changes: 4 additions & 0 deletions gitflow-common
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ git_local_branch_exists() {
has $1 $(git_local_branches)
}

git_remote_branch_exists() {
has $1 $(git_remote_branches)
}

git_branch_exists() {
has $1 $(git_all_branches)
}
Expand Down