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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:51:39+00:00 2026-05-27T22:51:39+00:00

I have a master branch and everything is fine in it. Then I create

  • 0

I have a master branch and everything is fine in it. Then I create a branch called experimental and I create a new file. While in my experimental branch I add this file using the git add command. Then I checkout my master branch. While in my master branch I run git status and discover that this file has also been added to my master branch. I then run git commit -m "message" while in my master branch and the commit happens. Then I switch to my experimental branch and run git status and discover that the file has also been committed in my experimental branch.

Here is what I would have expected: Upon switching to the master branch after adding the new file I would expect that the file would not appear there. After all, I did not create the file while in the master branch and I did not add the file while in the master branch. So when I switch to the master branch and run git status why does it find the file already added and ready to commit? And when I then do commit it while in the master branch, why do I also find it committed in the experimental branch when I switch back? Did it commit to two branches at once?

  • 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-27T22:51:40+00:00Added an answer on May 27, 2026 at 10:51 pm

    When you run git add, the file is not committed, it’s only added to Git’s “index”. You probably wanted to run git commit after doing git add on your experimental branch.

    When you switch branches in Git, the changes in your working directory and in the index are carried over as long as they don’t conflict with any other files that change during the branch switch.

    To address your specific concern:

    …and discover that this file has also been added to my master branch.

    If you haven’t run git commit, then the file has not yet been added to any branch at all.

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

Sidebar

Related Questions

I have master branch of the project. Then I want to add a new
I am using git and I have two branches: production and master. At this
Apologies for how basic this is..but remotely, I have a master branch and a
Originally, I had everything contained in my master branch. Then, I decided to split
I have a master branch, and another_branch with twice as many files in it.
I have a 'master' branch and several topic branches. Assume that the master branch
Given I have a master branch and a other branch. In the other branch
Somehow my master and my origin/master branch have diverged. I actually don't want them
I have already got a local master branch tracking the remote master branch of
We have a git based project with a friend and one master branch. He

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.