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 6960335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:23:22+00:00 2026-05-27T15:23:22+00:00

Git is allowing me to change branches when I have changes not staged for

  • 0

Git is allowing me to change branches when I have changes not staged for commit (modified files).

Is there a configuration for this somewhere?

Edit: At first I thought this was a configuration that I needed to set to disallow changing between branches if there are modified unstaged files. But by Emily’s comment, it appears that you’re prompted if the files differ between branches, and not prompted otherwise.

  • 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-27T15:23:23+00:00Added an answer on May 27, 2026 at 3:23 pm

    How it decides

    A quick experiment shows the following.

    Suppose you’re on branch dev and you’ve modified foo.txt. Without committing, you try to check out master. One of two things will happen.

    1. If foo.txt was modified in master in a commit that dev doesn’t have, you won’t be allowed to switch without committing, because master has a "new" version of the file that conflicts with the unstaged changes.

      To "check out" master, therefore, would require Git to update foo.txt to the newer version that master has, destroying your unstaged changes. To prevent your losing work, it won’t change branches.

    2. Otherwise, the modification has been done "since" the version master knows about, and you’ll be able to change branches. Git doesn’t have to update the file because master has no new information about the file.

    For the "whoops" changes

    Because of the above, if you have unstaged changes in files on one branch and realize you actually want to commit the changes on another, you may or may not be able to check out the other branch.

    You can, however, do the following:

    • git stash save "here's a summary of my changes" (summary will show up in git stash list)
    • git checkout otherbranch
    • git stash pop (which is a combination of git stash apply and git stash drop)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

git log lists all commits, from all branches that have been merged into HEAD.
git version 1.7.4.1 I am using git on Ubuntu. I have copied some files
git version 1.7.3.5 I have the following branches: git branch image master * video
git version 1.7.7.4 I have two branches development and testing . Originally testing was
git version 1.7.5.4 I have about 5 branches. All from the same initial branch.
Git says to use git add to add untracked files to my repo. I
Git is implemented as a directed acyclic graph. Children know their parents but not
My employer uses subversion for version-control, and this is unlikely to change. I'm interested
git status # On branch master # Changed but not updated: # (use git
I want to make changes to a file in my repo, then force git

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.