blob: 4c43b312511fd8729a3db44d18c64d82b19d038b [file] [log] [blame]
Vincent Driessen186d2b52010-01-27 23:48:39 +01001#
2# git-flow -- A collection of Git extensions to provide high-level
3# repository operations for Vincent Driessen's branching model.
4#
5# Original blog post presenting this model is found at:
6# http://nvie.com/archives/323
7#
8# Feel free to contribute to this project at:
9# http://github.com/nvie/gitflow
10#
11# Copyright (c) 2010 by Vincent Driessen
12# Copyright (c) 2010 by Benedikt Böhm
13#
14
15usage() {
16 echo "usage: git flow init"
17}
18
Vincent Driessen186d2b52010-01-27 23:48:39 +010019# Default entry when no SUBACTION is given
20cmd_default() {
21 echo
22 echo "Summary of actions:"
23
Vincent Driessen283b0f72010-02-15 23:23:14 +010024 if ! git rev-parse --git-dir >/dev/null 2>&1; then
Vincent Driessen186d2b52010-01-27 23:48:39 +010025 git init --quiet
26 echo "- A new git repository at $PWD was created"
27 fi
28
Vincent Driessen283b0f72010-02-15 23:23:14 +010029 if ! git rev-parse --quiet --verify HEAD >/dev/null 2>&1; then
Vincent Driessena4dd2232010-02-10 00:34:59 +010030 touch "$README"
31 git add "$README"
Vincent Driessen186d2b52010-01-27 23:48:39 +010032 git commit --quiet -m "initial commit"
33 if [ "$MASTER_BRANCH" != "master" ]; then
Vincent Driessena4dd2232010-02-10 00:34:59 +010034 git branch -m master "$MASTER_BRANCH"
Vincent Driessen186d2b52010-01-27 23:48:39 +010035 fi
36 echo "- An initial commit was created at branch '$MASTER_BRANCH'"
37 fi
38
Vincent Driessen283b0f72010-02-15 23:23:14 +010039 if ! git rev-parse --verify "$MASTER_BRANCH" >/dev/null 2>&1; then
Vincent Driessen186d2b52010-01-27 23:48:39 +010040 die "Cannot find your master branch. Try: git branch -m <mymaster> $MASTER_BRANCH"
41 fi
42
Vincent Driessen48386442010-01-29 10:30:40 +010043 gitflow_require_clean_working_tree
Vincent Driessen186d2b52010-01-27 23:48:39 +010044
Vincent Driessena4dd2232010-02-10 00:34:59 +010045 if git remote | grep -q "$ORIGIN"; then
46 git fetch -q "$ORIGIN"
47 gitflow_require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
Vincent Driessen186d2b52010-01-27 23:48:39 +010048 fi
49
Vincent Driessen283b0f72010-02-15 23:23:14 +010050 if git rev-parse --verify "$DEVELOP_BRANCH" >/dev/null 2>&1; then
Vincent Driessena4dd2232010-02-10 00:34:59 +010051 gitflow_require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
Vincent Driessen186d2b52010-01-27 23:48:39 +010052 else
Vincent Driessena4dd2232010-02-10 00:34:59 +010053 git checkout -q -b "$DEVELOP_BRANCH" "$MASTER_BRANCH"
Vincent Driessen186d2b52010-01-27 23:48:39 +010054 echo "- A new branch '$DEVELOP_BRANCH' was created"
55 echo "- You are now on branch '$DEVELOP_BRANCH'"
56 fi
57
Vincent Driessena4dd2232010-02-10 00:34:59 +010058 if ! git remote | grep -q "$ORIGIN"; then
Vincent Driessen186d2b52010-01-27 23:48:39 +010059 if [ "$1" = "" ]; then
60 echo "- No remote location was added. Try: git remote add $ORIGIN <url>"
61 else
Vincent Driessena4dd2232010-02-10 00:34:59 +010062 git remote add "$ORIGIN" "$1"
Vincent Driessen186d2b52010-01-27 23:48:39 +010063 echo "- A new remote location '$1' was added"
64 fi
65 fi
66
67 echo
68
Vincent Driessena4dd2232010-02-10 00:34:59 +010069 if git remote | grep -q "$ORIGIN"; then
70 git push "$ORIGIN" "$MASTER_BRANCH" "$DEVELOP_BRANCH"
Vincent Driessen186d2b52010-01-27 23:48:39 +010071 fi
72}
73
Vincent Driessenb866b012010-01-28 01:01:53 +010074cmd_help() {
75 usage
76 exit 0
77}