blob: 84ba142677ef68b319f584d9a8e677c606362dd5 [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
19cmd_help() {
20 usage
21 exit 0
22}
23
24# Default entry when no SUBACTION is given
25cmd_default() {
26 echo
27 echo "Summary of actions:"
28
29 if ! git rev-parse --git-dir 2>&1 >/dev/null; then
30 git init --quiet
31 echo "- A new git repository at $PWD was created"
32 fi
33
34 if ! git rev-parse --quiet --verify HEAD 2>&1 >/dev/null; then
35 touch $README
36 git add $README
37 git commit --quiet -m "initial commit"
38 if [ "$MASTER_BRANCH" != "master" ]; then
39 git branch -m master $MASTER_BRANCH
40 fi
41 echo "- An initial commit was created at branch '$MASTER_BRANCH'"
42 fi
43
44 if ! git rev-parse --verify $MASTER_BRANCH 2>&1 >/dev/null; then
45 die "Cannot find your master branch. Try: git branch -m <mymaster> $MASTER_BRANCH"
46 fi
47
48 gitflow_check_clean_working_tree
49
50 if git remote | grep -q $ORIGIN; then
51 git fetch -q $ORIGIN
52 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
53 fi
54
55 if git rev-parse --verify $DEVELOP_BRANCH 2>&1 >/dev/null; then
56 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
57 else
58 git checkout -q -b $DEVELOP_BRANCH $MASTER_BRANCH
59 echo "- A new branch '$DEVELOP_BRANCH' was created"
60 echo "- You are now on branch '$DEVELOP_BRANCH'"
61 fi
62
63 if ! git remote | grep -q $ORIGIN; then
64 if [ "$1" = "" ]; then
65 echo "- No remote location was added. Try: git remote add $ORIGIN <url>"
66 else
67 git remote add $ORIGIN $1
68 echo "- A new remote location '$1' was added"
69 fi
70 fi
71
72 echo
73
74 if git remote | grep -q $ORIGIN; then
75 git push $ORIGIN $MASTER_BRANCH $DEVELOP_BRANCH
76 fi
77}
78