Saulo
Saulo

Reputation: 559

What means to execute `git tag` with the branch name?

In this bitbucket-pipelines file the tag command looks like this:

git tag -am "Tagging for release ${BITBUCKET_BUILD_NUMBER}" release-${BITBUCKET_BUILD_NUMBER}`

I understand the use of variables in shell script. What is new to me is the use of what seems to be the branch name in the tag command (release-${BITBUCKET_BUILD_NUMBER}).

I'm used to create tag without specifying any branch: git tag -a v1.0 -m "My v1.0"

Why would I specify the branch name in the tag command?

I'm assuming release-${BITBUCKET_BUILD_NUMBER} is the branch name because the next command in the bitbucket pipelines is a push using this fragment as the branch name:

git push origin release-${BITBUCKET_BUILD_NUMBER}

I executed it in my local repo and I noticed my prompt has changed to somewhere I've never been before:

zsh robbyrussell themed shell

If I execute git status I'm still on task/XXXX-251 branch but I didn't get why my prompt changed. If you know oh-my-zsh robbyrussell theme and want to clarify this other part I'd appreciate!

Upvotes: 0

Views: 654

Answers (1)

KamilCuk
KamilCuk

Reputation: 141503

What means to execute git tag with the branch name?

git tag adds a tag that points to a commit. Branches point to a commit. git tag <tagname> <branch> means to tag the commit the branch points to. git tag <tagname> without a branch means to tag current HEAD.

The presented command does not use branch name.

git tag -am "Tag..." release-${BITBUCKET_BUILD_NUMBER}
                                                         ^^^^ - no branch
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - tag name
            ^^^^^^^^ - tag message
          ^          - next argument is a message

it's same as, i.e. you can mix flag arguments with positional arguments:

git tag -a v1.0 -m "My v1.0"
                   ^^^^^^^^^ - tag message
                ^^           - next argument is a message|
           ^^^^              - tag name

Upvotes: 1

Related Questions