Search code examples
gitgithubgithub-release

How to Merge a branch with a already released code?


I have a hotfix that needs to be applied to a already released code. I can get to the master of release but when I try to merge the branch, GitHub automatically changes the default branch to master. I am not sure how to do it from GitHub UI. Can someone help?

What I am trying to do:

  1. I've a release

enter image description here

  1. I did a hotfix but my current master is way ahead of release Test12. I need to add only this hotfix to Test12 release.

Solution

  • First, you do not want to add them to the Test12 release, you want to create a new release. Once you release code you shouldn't change it, because that will create a situation in which you have different code in the wild under the same name, which will just create confusion. If Test12 becomes totally irrelevant after you release the next one, and you don't want people to use it (totally broken, security vulnerability, etc), you can just delete the release.

    From your text it sounds like you have only one branch, master.

    A quick solution to get your fix released could be:

    1. Go back to the commit that matches your release and create a new branch based on that (which will have an associated tag, which seems to be called "1" from your screenshot) git checkout -b hotfix-branch 1
    2. Cherry-pick your hotfix from master with git cherry-pick <commit of hotfix>
    3. Create a new tag on that branch git tag -a 1.0.1 -m "Hotfix for issue..."
    4. Create a new release from that tag.

    Workflow notes:

    I noticed your version is only a single number. You should check out semantic versioning, the most commonly used three-decimal version system that uses each number to convey specific meaning, largely backwards-compatibility.

    If my guess was correct and you only have one branch, you should also check out git flow, the most commonly-used workflow for making doing things like release hotfixes easy.