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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:13:05+00:00 2026-06-12T16:13:05+00:00

I tried following commands on the shell git init echo test1 > test1.txt git

  • 0

I tried following commands on the shell

git init

echo "test1" > test1.txt
git add test1.txt
git commit -a -m "test1"

echo "test2" >> test1.txt

git branch test
git checkout test

text.txt now contains:

test1
test2

After checkout to branch test all local modifications from master get merged.

Why?

I expected that git refuses checkout to test because of the local changes. I expected that git asks for a commit or stash the local changes.

Edit:
I used a bash script to execute this commands. I get following output:

r@r:/tmp/test$ ./createrepo 
Initialized empty Git repository in /tmp/test/.git/
[master (root-commit) 0407f5b] test1
 1 file changed, 1 insertion(+)
 create mode 100644 test1.txt
M       test1.txt
Switched to branch 'test'
  • 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-06-12T16:13:07+00:00Added an answer on June 12, 2026 at 4:13 pm

    git tries hard to not lose possibly valuable data. In this case, it’s not actually merging branches, as the changes in question have not been committed. Rather, when you do a git checkout, it attempts to preserve newly made but not committed yet modifications, so it checks out the commit you are requesting, and adds your uncommitted changes. If you really want to discard the uncommitted changes, use git checkout -f, or git checkout followed by git reset --hard HEAD. Sometimes, if the changes you have not committed yet can’t be merged into what you’re checking out cleanly, you’ll get an error message and the checkout will fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't update the rubygems from 1.3.1 to 1.3.5. I've tried the following commands
The following command causes an exception. cv::imwrite(test.jpg, diffImg); I also tried numerous variations on
I'm trying to run the following commands: replace -x must A2input.txt replace -x a
So far I've tried the following commands: sudo apt-get remove mysql-server mysql-client mysql-common sudo
I tried the following command find ~/dir1 *.m4a | play Directory dir1 has exactly
I tried the following command unsuccessfully sdiff <(ping www.nato.int) <(ping www.reuters.com) Is there any
I tried to run the following command and it says there is nothing to
The following code utilizes CreateProcess to run commands with environmental variables. Here, it tries
Tried following the instructions here: How to use Google app engine with my own
I tried following the instruction s but can't get the plugin to work, the

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.