1

I am new to Git. I have checked new remote branch at my local. As I am checking out a new fresh branch from remote, I don't expect any local changes in the files of my repository.

But somehow few files show changes. I am using Git on Eclipse IDE.

Why is so? Have I misunderstood the concept of new fresh branch checkout?

Update

Based on comments by Tim Biegeleisen and Sajib Khan my understanding was wrong as it is expected behaviour when you check-out remote as a local branch any previous uncommitted changes in the working directory ( Repository ) will carry to the newly checked-out local branch.

Sanket
  • 11
  • 2
  • Why would you expect that switching branches would not possibly cause a change in the presence/absence of certain files? I don't see anything unexpected in what you describe. – Tim Biegeleisen Dec 01 '17 at 06:16
  • 1
    @TimBiegeleisen I have a fresh copy of remote i.e. no difference in local as well as remote then why few files show as they are changed? Do my previous local changes on other local branch carry into this new fresh remote-local checkout? – Sanket Dec 01 '17 at 06:19
  • Can you make sure that all changes are committed perfectly in the previous branch (`git status`) then, check out to remote branch? – Sajib Khan Dec 01 '17 at 06:21
  • 1
    I believe Git will carry changes in your working directory when you switch branches by default, with a few exceptions to that behavior. – Tim Biegeleisen Dec 01 '17 at 06:23
  • Possible duplicate of [Checkout another branch when there are uncommitted changes on the current branch](https://stackoverflow.com/questions/22053757/checkout-another-branch-when-there-are-uncommitted-changes-on-the-current-branch) – tkruse Dec 01 '17 at 06:30
  • Thanks, TimBiegeleisen and SajibKhan, I really appreciate your help :) – Sanket Dec 01 '17 at 06:32

1 Answers1

0

Just to put in simple words let me explain with example

Think that your working in master branch and add some new file (Eg file1.txt and file2.txt). Now you don't stage or commit these 2 files then it will be shown as untracked files.

Master Branch

Untracked  files
    file1.txt
    file2.txt

At this particular point of time you switch to another branch then the files which were untracked will be shown in the newly checkout branch.

To over come this problem you can go for the following 2 ways

  1. Stash the files from master branch and then switch to another branch, now it wont show the untracked files of master in newly switched branches. Stashing is nothing but saving the files and then reusing those at later point of time.

  2. commit amending

Channaveer Hakari
  • 2,769
  • 3
  • 34
  • 45