Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting directory in branch causes directory in master to be deleted on switch?

Tags:

git

In my git repo master branch i have working dir /tmp/repo_name/secret_code. If i switch to new branch called test and then rm -rf secret_code.. when i change back to master it deletes the secret_code directory from there as well.

I thought if i make changes on a git branch that it acts as a container for changes so on changing to another branch the working dir will reflect that branches state.

Why when i remove files from a branch are those actions reflected on my master branch ?

Thank you.

like image 330
Flo Woo Avatar asked Mar 19 '23 10:03

Flo Woo


1 Answers

Why when i remove files from a branch are those actions reflected on my master branch ?

Because you modified the working tree: when you switch back to master, if master didn't have modifications done on secret_code, it will keep the working tree as is, and the git status will reflect the deletion of that folder.

This would remove secret_code only in test branch:

git checkout test
git rm -r secret_code
git add -u .
git commit -m "removes secret_code in test"

Then:

git checkout master

You would still see secret_code in that master branch.

like image 173
VonC Avatar answered Mar 22 '23 08:03

VonC