Skip to content

Commit 444722c

Browse files
authored
Merge pull request #895 from vanpipy/feature/optional-start-point-when-creeate-branch
feat(#861): add optional parameter --from to set the start point
2 parents 18bcfcd + b2b5c97 commit 444722c

File tree

8 files changed

+78
-15
lines changed

8 files changed

+78
-15
lines changed

bin/git-create-branch

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ do
2020
REMOTE=origin
2121
fi
2222
;;
23+
--from)
24+
if [[ -n $2 ]]; then
25+
START_POINT=$2
26+
shift
27+
fi
28+
;;
2329
*)
2430
BRANCH=$1
2531
esac
@@ -44,9 +50,15 @@ then
4450
rm -f "$stderr"
4551
if [ $REMOTE_EXIT -eq 0 ]
4652
then
47-
git push $REMOTE HEAD:refs/heads/$BRANCH
48-
git fetch $REMOTE
49-
git checkout --track -b $BRANCH $REMOTE/$BRANCH
53+
if [[ -n $START_POINT ]]; then
54+
git fetch $REMOTE
55+
git checkout --track -b $BRANCH $START_POINT
56+
git push $REMOTE HEAD:refs/heads/$BRANCH
57+
else
58+
git push $REMOTE HEAD:refs/heads/$BRANCH
59+
git fetch $REMOTE
60+
git checkout --track -b $BRANCH $REMOTE/$BRANCH
61+
fi
5062
exit $?
5163
else
5264
echo
@@ -56,4 +68,9 @@ then
5668
fi
5769
fi
5870

59-
git checkout -b $BRANCH
71+
if [[ -n $START_POINT ]]
72+
then
73+
git checkout -b $BRANCH $START_POINT
74+
else
75+
git checkout -b $BRANCH
76+
fi

bin/git-feature

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ do
3232
--squash )
3333
merge_mode="--squash"
3434
;;
35+
--from )
36+
start_point=$2
37+
shift
38+
;;
3539
* )
3640
argv+=($1)
3741
;;
@@ -55,10 +59,24 @@ else
5559
else
5660
branch="$branch_prefix"/"${argv[0]}"
5761
fi
58-
if [[ -n $remote ]]
62+
63+
if [[ -n $remote ]] && [[ -z $start_point ]]
5964
then
6065
git create-branch -r $remote $branch
61-
else
66+
fi
67+
68+
if [[ -z $remote ]] && [[ -z $start_point ]]
69+
then
6270
git create-branch $branch
6371
fi
72+
73+
if [[ -n $remote ]] && [[ -n $start_point ]]
74+
then
75+
git create-branch -r $remote --from $start_point $branch
76+
fi
77+
78+
if [[ -z $remote ]] && [[ -n $start_point ]]
79+
then
80+
git create-branch --from $start_point $branch
81+
fi
6482
fi

man/git-create-branch.1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "GIT\-CREATE\-BRANCH" "1" "June 2019" "" "Git Extras"
4+
.TH "GIT\-CREATE\-BRANCH" "1" "November 2020" "" "Git Extras"
55
.
66
.SH "NAME"
77
\fBgit\-create\-branch\fR \- Create branches
@@ -19,6 +19,12 @@ Creates local branch named <branchname> and optionally sets up a remote tracking
1919
Setup a remote tracking branch using \fBremote_name\fR\. If \fBremote_name\fR is not supplied, use \fBorigin\fR by default\.
2020
.
2121
.P
22+
<\-\-from [start_point]>
23+
.
24+
.P
25+
Setup a start point when the branch created\. If \fB\-\-from\fR is not supplied, use the current branch by default\.
26+
.
27+
.P
2228
<branchname>
2329
.
2430
.P

man/git-create-branch.html

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-create-branch.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Creates local branch named &lt;branchname&gt; and optionally sets up a remote tr
1515

1616
Setup a remote tracking branch using `remote_name`. If `remote_name` is not supplied, use `origin` by default.
1717

18+
&lt;--from [start_point]&gt;
19+
20+
Setup a start point when the branch created. If `--from` is not supplied, use the current branch by default.
21+
1822
&lt;branchname&gt;
1923

2024
The name of the branch to create.

man/git-feature.1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "GIT\-FEATURE" "1" "April 2020" "" "Git Extras"
4+
.TH "GIT\-FEATURE" "1" "November 2020" "" "Git Extras"
55
.
66
.SH "NAME"
77
\fBgit\-feature\fR \- Create/Merge feature branch
@@ -28,6 +28,12 @@ use \fBbranch_prefix\fR instead of \fBfeature\fR
2828
Setup a remote tracking branch using \fBremote_name\fR\. If \fBremote_name\fR is not supplied, use \fBorigin\fR by default\.
2929
.
3030
.P
31+
<\-\-from [start_point]>
32+
.
33+
.P
34+
Setup a start point when the branch created\. If \fB\-\-from\fR is not supplied, use the current branch by default\.
35+
.
36+
.P
3137
<finish>
3238
.
3339
.P

man/git-feature.html

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-feature.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ git-feature(1) -- Create/Merge feature branch
2020

2121
Setup a remote tracking branch using `remote_name`. If `remote_name` is not supplied, use `origin` by default.
2222

23+
&lt;--from [start_point]&gt;
24+
25+
Setup a start point when the branch created. If `--from` is not supplied, use the current branch by default.
26+
2327
&lt;finish&gt;
2428

2529
Merge and delete the feature branch.

0 commit comments

Comments
 (0)