git is 'M'erging un-committed edits when changing branches?

Update: according to the link in my question below, ‘M’ seems to mean Merge’d when you see it during a branch change, but Modified with git status: “When we switch to the master branch, the working directory is considered “dirty” since the README file has not been added to the index and committed. As a result, git will attempt to merge the contents of README from the test branch into the README file in the master branch:”

Forgive my git ignorance, but why is it when I make changes in an upstream branch, and then checkout my master branch (without commit’ing), the modified file follows the current branch as a Merge? I thought git only merged when I told it to merge. I don’t always want my edits to propogate to another branch so is there a way to tell git to ask before merging?

  • Delete multiple remote branches in git
  • Undo “git stash --patch”
  • XCode 7: Can't Push git
  • How to deny branching from master
  • How to make git output show red or orange color when it contains the word “error”, “warning”, or “Aborting”?
  • Is there any way to configure git to lock a file when a user work on it?
  • iow: How can I tell git to keep me from screwing up another branch if I acccidentally switch to it with un-commit’d edits in my current branch?

    [on branch:foo]
    $ echo test >> main.c
    
    [on branch:foo]
    $ cat main.c 
    #include <stdio.h>
    
    int main void (int argc, char **argv)
    {
       printf ("Hello world!\n");
       return (0);
    }
    test
    
    [on branch:foo]
    $ git checkout master
    M       main.c
    Switched to branch 'master'
    
    [on branch:master]
    $ cat main.c 
    #include <stdio.h>
    
    int main void (int argc, char **argv)
    {
       printf ("Hello world!\n");
       return (0);
    }
    test
    
    [on branch:master]
    $   
    

  • Multiple repositories in one directory
  • Git Mirroring Issue
  • How to set the working directory to an older commit?
  • Accidentally merged other branches when using `git pull` with no arguments
  • Build operation failed without specifying any errors for React Native XCode project
  • Git post-receive hook to update a local clone owned by a different user
  • 2 Solutions collect form web for “git is 'M'erging un-committed edits when changing branches?”

    It depends on what you want to do with the changes.

    If you wanna throw them away use git checkout -f master

    If you wanna save them for later, git stash the changes to clean the working tree and git pop to apply the changes again whenever and wherever you want.

    If you want the changes to stay in the branch, just git commit the changes before git checkout master.

    M stands for modified meaning, you have a modified version in your working directory. A.K.A. you have changes you have not yet committed.

    Your uncommitted changes go along for the ride when you change branches. If you want to change branches, but are not ready to commit them you could stash them using git stash and later restore them using git stash pop

    Git Baby is a git and github fan, let's start git clone.