millie
millie

Reputation: 2905

Freezing a Git branch

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 shown here:

enter image description here

Is there a way I can freeze the feature branch so that no further commits can be made to it?

The reason for not outright deleting the branch is so that viewing the history can still show the feature branch and that if there needs to be a tweak made to the feature then it is possible for someone to create a new feature branch from the last commit of the previous feature.

Upvotes: 31

Views: 45482

Answers (5)

BHUVANESH MOHANKUMAR
BHUVANESH MOHANKUMAR

Reputation: 2787

I am using the "Git Bash" console to freeze the branch:

[Solution worked Best during Oct 2018]

Don't have Git Bash?

Here is how to install and use the Git Bash console:

Reference:

https://github.com/msysgit/msysgit/releases/

https://help.github.com/articles/set-up-git/

How to freeze a branch

git checkout {branch-to-keep-alive}
git merge --no-ff {branch-to-freeze} 

If git asks for a merge message, type it, then use [Esc] key then type ":wq" command to save and exit.

You have to go to visual studio and make sure that you can build the solution successfully (with {branch-to-keep-alive}).

git checkout {branch-to-freeze} 

git tag -a -m "{your-description}" {tag-for-the-branch-to-freeze}

Convention: create the tag like this: {branch-name}_frozen

git checkout {branch-to-keep-alive}

git branch -d {branch-to-freeze} 

git push --tags origin {branch-to-keep-alive}

git push origin :{branch-to-freeze} 

How to merge a branch with master:

git checkout {your-working-branch} 

Git merge master

Open vs and resolve merge conflicts if there is any. Always rebuild the whole things.

git checkout master
git merge development

There won't be any conflicts now and everything is set to go.

Git Bash Console:

enter image description here

Upvotes: -2

gjcamann
gjcamann

Reputation: 651

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

Upvotes: 25

Philip Oakley
Philip Oakley

Reputation: 14101

Consider git-freeze as mentioned in Git - Branch status (frozen, inactive, etc.).

Upvotes: 1

Christopher
Christopher

Reputation: 44304

Just tag it.

git tag -a frozen -m "Feature branch frozen here."
git push <remote> frozen

Sure, someone could come along later and push to the branch, but the tag shouldn't change unless it's forcibly overrode. You could configure your remote to reject force pushes if you're concerned about it, or even sign the tags with a GPG key to ensure authenticity.

Getting the state of the feature branch when it was frozen is as simple as git checkout frozen. Developers can branch from this point at will using one command: git checkout -B <new_branch> frozen.

Upvotes: 10

Fatih Arslan
Fatih Arslan

Reputation: 17157

You could use something like gitolite or gerrit for access controls and permission along branches, tags and repos.

Have a look here:

Upvotes: 2

Related Questions