Skip to content

Commit 37f1a51

Browse files
author
Linus Torvalds
committed
Add "git branch" script
You can use it as git branch <branchname> [start-point] and it creates a new branch of name <branchname>. If a starting point is specified, that will be where the branch is created, otherwise it will be created at the current HEAD. The sequence git branch xyz abc git checkout xyz can also be written as git checkout -b xyz abc as per the previous commit.
1 parent 91dcdfd commit 37f1a51

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ SCRIPTS=git git-apply-patch-script git-merge-one-file-script git-prune-script \
3434
git-log-script git-shortlog git-cvsimport-script git-diff-script \
3535
git-reset-script git-add-script git-checkout-script git-clone-script \
3636
gitk git-cherry git-rebase-script git-relink-script git-repack-script \
37-
git-format-patch-script git-sh-setup-script git-push-script
37+
git-format-patch-script git-sh-setup-script git-push-script \
38+
git-branch-script
3839

3940
PROG= git-update-cache git-diff-files git-init-db git-write-tree \
4041
git-read-tree git-commit-tree git-cat-file git-fsck-cache \

git-branch-script

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
. git-sh-setup-script || die "Not a git archive"
4+
5+
branchname="$1"
6+
rev=$(git-rev-parse --verify --default HEAD "$2"^0) || exit
7+
8+
[ -z "$branchname" ] && die "git branch: I want a branch name"
9+
[ -e "$GIT_DIR/refs/heads/$branchname" ] && die "$branchname already exists"
10+
11+
echo $rev > "$GIT_DIR/refs/heads/$branchname"

0 commit comments

Comments
 (0)