Skip to content

Git Tags and Commands

Procedure after Merge Merge on GitLab

When a merge request on GitLab has been performed with deleting the branch, the local branch is not deleted.

Delete the local branch

Move to the main branch and delete the branch e.g. dev-hotfix.

git checkout main
git fetch --prune
git pull origin main
git branch -d dev-hotfix

Reuse local branch

Fetch all changes check out the branch if not the current one and hard reset the branch using the main branch.

git fetch origin
git checkout dev-hotfix
git reset --hard origin/main

The branch can now be pushed to the remote repository again.

git push origin dev-hotfix

Local Tag Listing

To list all local tags.

git tag -l
git tag --list
git show-ref --tags 

List the tags including the annotated message.

git tag -l -n
git tag --list -n

Remote Tag Listing

List tags on remote (GitLab?).

git ls-remote --tags
git ls-remote --tags origin
When a tag is annotated the listing contain also an entry ending with ^{}.

Add a tag

There are 2 ways of creating a tag, with (annotated) or without (lightweight) a message.

git tag my-tag-name

The Annotated version.

git tag -a my-tag-name -m "My annotated message for this tag."
git tag --annotate my-tag-name --message="My annotated message for this tag."

Pull Tags from Remote

git pull --tags

In case of a shallow clone it tags are not all retrieved and --force makes it so.

git pull --tags --force

Push Tags to Remote

Update remote having the new created local tags.

git push --tags

When a tag is deleted and created to a different commit hash the remote is not taking it so add the --force option.

git push --tags --force

Delete a Tag

Deleting a local tag.

git tag -d my-tag-name
git tag --delete my-tag-name

Deleting a tag on a remote repository.

git push --delete origin my-tag-name
git push origin :my-tag-name

Log entries since branching of main

git log --pretty=format:"%s" $(git merge-base main HEAD)..HEAD