My First Post      My Facebook Profile      My MeOnShow Profile      W3LC Facebook Page      Learners Consortium Group      Job Portal      Shopping @Yeyhi.com

Pages










Showing posts with label version control. Show all posts
Showing posts with label version control. Show all posts

Monday, February 16, 2026

My Code Disappeared After Switching Branches — Here’s What Actually Happened

 Yesterday I panicked.

I switched from a feature branch back to main in Git…

…and my fix was gone.

The file didn’t show the changes.
The bug fix disappeared.
I thought I lost my work.

If this has ever happened to you — relax.

Your code probably isn’t lost.




😰 What Actually Happened?

I had:

  • Created a branch: feature-x

  • Fixed a bug

  • Committed the fix

  • Switched back to main

When I checked the file in main, the fix wasn’t there.

Why?

Because Git branches are independent timelines.

My fix existed.
Just not in main.


🧠 The Important Concept

Think of branches like parallel universes.

When you commit inside feature-x, that commit belongs to that branch.

Switching to main doesn’t magically bring those commits with you.

You must merge them.


✅ How I Fixed It

I ran:

git checkout main git merge feature-x

Boom.

The changes appeared.

Then I pushed to GitHub:

git push origin main

Problem solved.




🔎 How To Debug If This Happens To You

Here are the commands that save you:

1️⃣ Check where you are

git branch

2️⃣ See commits across branches

git log --all --oneline --graph

3️⃣ Compare branches

git log main..feature-x

4️⃣ Recover “lost” commits

git reflog

Nothing is usually lost.
It’s just on another branch.


🚀 Lesson for Developers

Before panicking:

  1. Check your branch

  2. Check your commits

  3. Understand Git timelines

  4. Merge properly

  5. Push if needed

Git rarely deletes your work.
It just organizes it.


💡 Final Thought

The biggest Git mistake is not a wrong command.

It’s not understanding branches.

Once you understand that each branch is a separate history —
Git becomes predictable.

And panic disappears.

Friday, March 24, 2017

Git : Rename / Change Branch name : How to Change the branch name of a local or a remote branch in git

There are multiple scenarios if you want to change the name of the branch. Sometimes you could have named a branch incorrectly, and sometimes it could be because you didn't follow the naming guidelines as per your team and organisation. Whatever be the cause, you very well need to know the method to do so.


The process is as follows:

1. First, rename your local branch.  (Sometimes you need to only do this. For example if the branch is yet not pushed on stash.)
If you are on the branch you want to rename:
Syntax: git branch -m new-name


2. In case you are on a different branch:
Syntax: git branch -m old-name new-name


3. Now suppose you want o delete the old remote branch and push the new-name local branch.
Syntax: git push origin :old-name new-name


Or, 4. You can also reset the upstream branch with the new branch local branch.
For this you need to switch to your new local branch and then:
Syntax: git push origin -u new-name