Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6805251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:33:51+00:00 2026-05-26T19:33:51+00:00

I am having an issue with Git branching. Whenever I make changes to a

  • 0

I am having an issue with Git branching. Whenever I make changes to a branch, all those changes get reflected in master branch even though I haven’t invoked explicit merge command.

For example,

I created a “dashboard” branch git checkout -b dashboard

then I have made changes in one of my file(say routes.rb) and now I switched to master git checkout master

Now when I open routes.rb, i can see the changes from dashboard branch. Why? Do I have some git settings that should not be there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:33:52+00:00Added an answer on May 26, 2026 at 7:33 pm

    When you make changes, those changes only exist in your working tree up until to the point when you commit them.

    When you switch branches, Git will carry changes in your worktree over to the new checkout. This is often helpful when you notice that you were working on the wrong branch.

    There’s even a recent discussion about this “unexpected” behavior on the Git mailing list about this. To quote Junio:

    “J.V.” gmail.com> writes:

    OK so “work tree” is a new term for me. I thought we were in isolated
    sandboxes called “branches” and changes made in a branch would stay in
    that branch regardless.

    Do not think of “branches” as isolated sandboxes.

    Rather, “branches” are where the independent states are to be
    recorded.

    The recorded states only exist in the git repository, and to use its
    contents (e.g. view in the pager or browser, edit in the editor, run
    the compiler on,…), you need to materialize the contents of the
    branch somewhere on the filesystem. Such a set of files on the
    filesystem form the working tree. The act of doing so is called
    “checking out a branch”.
    […]


    Edit

    Just in case if above link becomes void

    Problem

    Unexpected git behaviour 
    
    --- 
    # First create a local git repo 
    
    $mkdir gitexample 
    $git config --global user.name "my name" 
    $git config --global user.email "me@me.com" 
    $git init 
    $git add . 
    $git commit -m 'initial commit' 
    
    # Create/Edit an empty file 
    $vi readme.txt 
    
    # add a single line: "this was added in the master branch." 
    $git commit -a 
    
    # create and checkout a new branch (from master) 
    $git branch test 
    $git checkout test 
    
    # edit the readme.txt file and do not commit 
    # add the text:  "this was added in the test branch.", save and exit 
    $vi readme.txt 
    
    #now switch back to master 
    $git checkout master 
    $cat readme.txt 
    
    #You will see both lines in the master.   
    
    Question #1: 
            Why was this line added in the *master branch? 
    
    
    --- even further surprising 
    In the master branch, now do a commit 
    $git commit -a 
    
    cat readme.txt ( you will see the line in the master now that was added in the test branch ) 
    
    Question #2: 
            Why did this happen? 
    
    # Now switch back to the test branch 
    $git checkout test 
    $cat readme.txt 
    
    You will only see the one line: "This was added in the master branch" 
    
    Question #3: 
            Why did this happen? 
    
    and NOT the line added in that branch: "this was added in the test branch" <= this line is gone 
    
    What is the reason for this? 
    
    1) Why do I see uncommitted changes in the branches made off master in the master branch? 
    2) Why, if I commit them in the master, do the disappear in the branch in which they were made? 
    
    This is confusing, I would think the * master branch would be left untouched.  This would solve issue #2. 
    

    Reply

    On Fri, Nov 11, 2011 at 12:55:04PM -0800, Jvsrvcs wrote: 
    > Unexpected git behaviour 
    > 
    [ ... switch branches with local modifications ...] 
    > #You will see both lines in the master.   
    > 
    > Question #1: 
    > Why was this line added in the *master branch? 
    > 
    
    It wasn't. that line was added in the working directory. When you 
    switch branches, if the file in the tip of the current branch and the 
    file in the tip of the target branch don't differ, it's safe to keep 
    your local changes, so git does. This is to support the use-case where 
    you start editing a file when the wrong branch is checked out and want 
    to change to the right one. 
    
    > 
    > --- even further surprising 
    > In the master branch, now do a commit 
    > $git commit -a 
    > 
    > cat readme.txt ( you will see the line in the master now that was added in 
    > the test branch ) 
    > 
    > Question #2: 
    > Why did this happen?
    ... [show rest of quote]
    ... [show rest of quote]
    Because you told git to commit the file with that modification in it. 
    
    > 
    > # Now switch back to the test branch 
    > $git checkout test 
    > $cat readme.txt 
    > 
    > You will only see the one line: "This was added in the master branch" 
    > 
    > Question #3: 
    > Why did this happen? 
    
    Because the file in the 'test' branch only has that line. As you said 
    yourself, you edited the file but didn't commit. 
    
    > 
    > and NOT the line added in that branch: "this was added in the test branch" 
    > <= this line is gone 
    
    Again, that line wasn't added in any branch but in the working 
    directory. The active branch was 'test', but doesn't magically mean 
    that uncommitted changes travel with it. 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue with rebasing from master on to a 'deploy' branch
I am having issue with git pull.I have commited my changes in local repo.
The issue I'm having is issue with is I'm trying to get the paintComponent
I'm having an issue. I have switched to a branch some-feature . I do
I'm having an issue executing jruby from the mingw git bash shell in windows.
One of my coworkers is having a problem pushing changes from git on his
Having an issue with random individuals trying to access an intranet site with a
Having an issue here that I have tried everything I can think of but
I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS
I'm having an issue with my regex. I want to capture <% some stuff

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.