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:
- Switch to the branch with
git checkout 201718
- Check the switch happened with
git branch
- Create a tag with
git tag 201718
- Switch to the
master
branch;git checkout master
- 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. - Push the tag to the remote repo with
git push --tags
- 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 usegit 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