How to Tag in GIT

TAGGING A GIT BRANCH

Show all tags

git tag

Search tag

git tag -l "tag-search-pattern"
E.g.
git tag -l "v2.0.2*"

Create annotated tag

git tag -a <tagname> -m "<message>"
E.g.
git tag -a v2.0 -m "This version 2.0 contains web-ui changes"

Show tag details

git show <tagname>
E.g.
git show v2.0

Checkout tags

git checkout -b <branchname> <tagname>
E.g.
git checkout -b version2.0 v2.0

Pushing tags to remote

git push origin <tagname>
E.g.
git push origin v2.0

Pushing all (un-pushed) tags to remote

git push origin --tags

Rename an annotated git tag

  • rename tag
git tag <new-tag> <old-tag>
E.g.
git tag v1.1 1.1
  • delete tag locally
git tag -d <old-tag>
  • push deleted tag-change to remote
git push origin :<old-tag>
E.g.
git push origin :refs/tags/1.1
OR
git push origin :1.1
  • push renamed tag to remote
git push origin <new-tag> (E.g. git push origin v1.1)
OR
git push --tags
  • Finally, make sure that the other users remove the deleted tag. Please tell them(co-workers) to run the following command:
git pull --prune --tags

List local branches with corresponding HEAD hash, sorted by last commit date

git for-each-ref --sort=-committerdate refs/heads/

* The Content stated above is for informational purpose only. Expert Software Team is not responsible if any part of content found meaningless in any manner or condition.

How to Compare Branch in GIT

COMPARE BRANCH

  • Compare two branches (local) and show how much commits each branch is ahead of the other
git rev-list --left-right --count <branch1>...<branch2>

DIFF STATUS

  • Get differences status between local (checked-out) branch and its respective remote (tracked) branch
git checkout <local-branch>
git status -sb
Example Output: ## <local-branch>...<remote-branch> [ahead 2, behind 1] 

DIFF AHEAD revisions of local branch

  • To see differences of ahead-revisions (in local-branch)
git diff <local-branch>...<remote-branch>^
E.g.
git diff master...origin/master^ 

DIFF BEHIND revisions of REMOTE branch

  • To see differences of ahead-revisions (in local-branch)
git diff <remote-branch>...<local-branch>^^
E.g.
git diff origin/master...master^^

* The Content stated above is for informational purpose only. Expert Software Team is not responsible if any part of content found meaningless in any manner or condition.