1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gitの現在ブランチ名を取得(*なしで)

Posted at

答え

branch_name=$(git describe --contains --all HEAD)

当初の方法

git branch --contains
* master

だから配列で受けて[1]を取ればいけそうな……

echo_branch_name.sh
array=($(git branch --contains))
echo ${array[1]}
$ sh echo_branch_name.sh
api

……あれ?「api」はどこから出てきた?

(しばし考える)

はっ!*が展開されてるー!

echo_branch_name2.sh
array=$(git branch --contains)
branch_name=${array:2} # * を除外
echo $branch_name
$ sh echo_branch_name2.sh
master

できた!

その後、「答え」の方法に気づきました。

1
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?