Git Release Tag and Branch

Release Tag

When to use tag: every time you push to production, tag the release. Release tag points to a specific commit in history.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# fetch all remote tags
git fetch --tags
# list all tags
git tag [--list]
# delete tag
git tag -d <tag name>
# Delete a tag from the server with push tags
git push --delete origin <tag name>

# in your current branch tag latest commit
# create annotated tag, add more info
# will open editor
git tag -a 0.1.0

# tag specific commit
git tag -a 0.1.0 <commit hash>

# push tag to remote
git push origin <branch> --tags

这个git command很有用

1
2
## can see commit detail, tag annotation, and so on.
git show [tag|or anything]

References: what is tag annotated and non-annotated tag move a tag on a branch to different commit

Release Branch

Generally you only need tags for releases. But when you need to make changes to production release without affecting master, you need release branch. For example, make hotfix. Release branch can be updated with new commits.

Use cases for release branches:

  • Manual QA.
  • Long running releases.
  • On demand hot fixes.

Workflow is like

1
2
3
4
5
6
7
# we have some hot fixes on release branch, then create a release tag on it for production
# finally merge into master
master ------ + ----- + -----+ --- + --------------- + ------>
\ /
\ hotfix hotfix /
\-------- + ----- + --------/
release branch (release tag)

[x] This is why we have double-commit back to master branch. 我们把release tag放在master branch中了。

You can also create release branch on the fly from release tags, the workflow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# on master branch
# checkout to a tag (detched HEAD)
git checkout v1.1
# create release branch on release tag
git checkout -b rb1.1

# or in one command to checkout a tag to a new branch
git checkout tags/v1.1 -b rb1.1

# make fix
<hot fix>

# commit
git commit -m "hotfix"
git tag -a v1.1.1 -m "hotfix"
# merge
git checkout master
# or rebase/squash or fast-forward
git merge rb1.1 -m "merged hotfix"
# delete branch, the tag is still there, because you merged to master
git branch -d rb1.1
0%