Branching Strategy

 

Before Taking a Hotfix – Create a copy of your main branch

You can create a backup branch or a Git tag from the current main branch before applying a hotfix.

Option 1 — Create Backup Branch

Step 1: Go to main branch

git checkout main

Step 2: Pull latest code

git pull origin main

Step 3: Create backup branch

git checkout -b release/1.0-backup

Step 4: Push backup branch to remote

git push origin release/1.0-backup

Now you have:

main

└── release/1.0-backup

 

Option 2 — Create Git Tag (Recommended for Production)

Tags are commonly used for production snapshots.

Step 1: Go to main

git checkout main

Step 2: Pull latest code

git pull origin main

Step 3: Create tag

git tag v1.0-production-stable

Step 4: Push tag to remote

git push origin v1.0-production-stable

Now you have a production snapshot:

main

└── tag: v1.0-production-stable

 

Backup Branch

Git Tag

Editable

Read-only snapshot

Used for temporary backups

Used for production releases

Can receive commits

Usually, immutable

More clutter if many backups

Cleaner release management

 

Option 1 — Roll back using Git Tag (recommended)

Current Production = bad hotfix

Previous stable version tag = v1.0-production-stable

 

Suppose:

Current Production = bad hotfix

Previous stable version tag = v1.0-production-stable

Move main back:

git checkout main

git reset --hard v1.0-production-stable

git push origin main –force

Then deploy production again.

 

Bad Hotfix

   

Production issue found

   

Reset main → stable tag

   

Deploy previous stable build

 

Option 2 — Roll back using backup branch

If backup branch exists:

release/1.0-backup

Go to main:

git checkout main

Reset to backup branch:

git reset --hard release/1.0-backup

git push origin main –force

 

Option 3 — Safer enterprise method (preferred): Revert commit

Instead of rewriting Git history (reset --hard), enterprises often use:

See bad commit:

git log

Example:

a12345 Hotfix login fix

b67890 Previous stable

Revert bad hotfix:

git revert a12345

git revert a12345 does not delete the bad commit.

Instead, it creates a new commit that cancels (undoes) the changes introduced by commit a12345.

 

Comments

Popular posts from this blog

Azure Migrate

Azure -- All Networking Components

All Kuberneters - Components