1

I am learning git commands through tutorials. I have one doubt:

inside a directory, which i want to make git compatible:

git init
git add .
git commit -m "initial commit of full repository"
git remote add origin bitbucket_URL
git push -u origin --all
git checkout -b feature/feature1
git rm README.txt
git add .
<didn't commit>
ls => doesn't show README.txt
git checkout master
ls => it also doesn't show README.txt 

but I had deleted README from feature1 branch NOT from master. why README is not showing up in ls of master branch

PS: But when I commit after adding in feature1 branch and then switch to master branch and then do ls, then README file shows up. Could someone please explain what is happening underneath

Paolo
  • 21,270
  • 6
  • 38
  • 69
BioLogic
  • 49
  • 7
  • But when I commit after adding in feature1 branch and then switch to master branch and then do ls, then README file shows up. Could someone please explain what is happening underneath... – BioLogic May 02 '20 at 14:35
  • 1
    You are allowed to carry uncommitted changes around when you `git checkout` some other branch. For details, see https://stackoverflow.com/q/22053757/1256452 – torek May 02 '20 at 15:00

1 Answers1

1

Until you commit, changes are up in the air. You moved to master, changes come with you.... if you had committed on the feature branch, if you checkout master, you would see the file show up..... and no, it's not a bug, it's a feature (how many times have you started working on the wrong branch? Or tested a few changes on different branches without having to commit to move around? Well, there you go!!!).

eftshift0
  • 26,375
  • 3
  • 36
  • 60