Freezing a Git branch

后端 未结 5 741
悲哀的现实
悲哀的现实 2020-12-29 04:20

Let\'s say I have a develop branch. I create a feature branch from this to develop a feature. Once the feature is developed, it is merged back into develop. Pretty much like

5条回答
  •  悲哀的现实
    2020-12-29 04:46

    Christopher is right, tagging will help you do this. I recommend deleting the branch name too to make it a little harder for someone to checkout the branch and make edits.

    First, merge the branch into develop

    git checkout develop
    git merge --no-ff feature_1 
    

    Then checkout the branch

    git checkout feature_1
    

    Then create a tag, with a comment.

    git tag -a -m "Freezing a feature branch that fixes.." feature_1_frozen
    

    Then delete the branch

    git checkout develop
    git branch -d feature_1
    

    After doing this, you won't be able to checkout the branch by name. Instead you'll be able to checkout the tag by name, this will put you into a detached head state which will deter changes to the code.

    Now to wrap things up and sync with origin...

    Push the update and new tag

    git push --tags origin develop
    

    Delete the remote feature branch

    git push origin :feature_1
    

提交回复
热议问题