I’m just starting with git.
I’ve cloned main from sourcetree, got all files in the folder. Then I created a branch, then another branch, but in my local copy it’ still only one copy of all the folders. But if I need locally change files in one branch but have them unchanged in another, how can I make every branch create different local copy?
Sounds like you have a subversion (or similar) background. That’s the default way to use git. A single working tree that you use to move around in the separate branches. If your background is on svn, imagine what it would be to have a single
working copy and use
svn switch to move around instead of creating more
working copies. It’s more or less the same… except that moving around is extremely fast because checkout operations are local. Here is probably the most important thing for your question: when you switch from one branch to the other, the files will be changed to the branch you are switching to in your working tree.
It’s possible to have more than one working tree, through
# add a couple of working trees git worktree add dir1 main # create a worktree in directory dir1 that uses branch main git worktree add dir2 dev # create a worktree in directory dir2 that uses branch dev git worktree list # show the 3 worktrees that you now have
But if you are a beginner, I would advice you to use a single working tree until you get the hang of it…. unless you have a real need for it.
Answered By – eftshift0