4

Should I put the master and other branch in separate folders?

For example, I have a folder called myF/. And I clone a project called whatever. And whatever is consist of two files -- a.txt, b.txt.

cd myF
git clone whatever

Then I create a branch called feature0.

git branch feature0

Now if I change anything to a.txt or b.txt, it will change both master and feature0.

Should I keep master untouched? And only change files in feature0?

Kevin217
  • 724
  • 1
  • 10
  • 20
  • 2
    Are you used to using SVN? Git doesn't work in the same way. It only ever has one copy of the files on disk. When you switch branches, it changes the existing directory structure to be that of the branch you are now on. – adrianbanks Dec 06 '16 at 21:44
  • @adrianbanks I see. Thanks. – Kevin217 Dec 06 '16 at 21:47
  • I think you should look into how git commits and branches work. Here's a good overview: https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell – cmrn Dec 06 '16 at 22:08

1 Answers1

3

Now if I change anything to a.txt or b.txt, it will change both master and feature0.

No it won't: it will be added and committed in the current branch (feature0)

x (master)
 \
  y (feature0)

Generally, you keep one working tree (one folder) for all branches and you switch the content of said working tree.

But since Git 2.5, you can indeed have separate working trees (one per branch) for one cloned repo: see git worktree that I mention here and with more details, in this answer.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250