Git new file appears in all branches

I thought a file created on one branch will not appear in any other branches until I merge or rebase the branch?

Example:

I have two branches:

  1. master
  2. new_contact_page

I checkout the new_contact_page branch.

$ git checkout new_contact_page

Then I create a new file.

$ vi contact_page.html

Without doing any Git commands, I switch back to my Master branch.

$ git checkout master

Then I see that this contact_page.html file is also in my Master branch.

$ ls   (contact_page.html shows up in the list!)

Shouldn't the file only exist in new_contact_page branch?

Answers


Git will never touch any files that aren't actually in your repository. (untracked files)

You need to git add and git commit the file (into one branch) first.


Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.