User Tools

Site Tools


howto:git_create_tag_from_branch

Create a Tag from a Branch using Git

So you have realized your whole assignment repo. is incorrectly structured with dead-end commits in branches you will never get back to. The solution across many timelines is to use tags and not branches. So how do we rectify the situation?

Consider a branch 201718 we want to convert to a tag (same name). Follow these instructions:

  1. Switch to the branch with git checkout 201718
  2. Check the switch happened with git branch
  3. Create a tag with git tag 201718
  4. Switch to the master branch; git checkout master
  5. Delete the branch locally with git branch 201718 -d. Note that this may give you an error if the branch was not merged error: The branch 'xxx' is not fully merged.
  6. Push the tag to the remote repo with git push --tags
  7. Delete the branch from the remote repository. This git push origin --delete 201718 won't work as there is also (now) a tag with the same name. As a workaround use git push origin :heads/201718 to delete this branch from the remote repo.
howto/git_create_tag_from_branch.txt · Last modified: 2021/03/23 15:58 by jp