I want to pour on githab. When I switch ( git checkout ) between the branches I previously created, then, respectively, in the directory and file tree everything is updated accordingly to the branch to which I moved. Now from the master branch I want to create a new branch ( git branch ) to fill in a new dz, but for some reason, when I create a new branch, then from it I see all the other folders and files that are in other branches, and from others branches are only visible to them. I thought it was because I made the git pull command and pulled all the changes (maybe wrong). And I decided to fill in the created branch, from which all the others are visible. Then I went to the githab, followed this branch and I see that my very first homework is in it, but it shouldn't be like that. What am I doing wrong?

  • as if a tree, not a bush, a branch grows from the place where it was announced - Sergey Panasenko
  • Yes, everything is not so! ;) In an amicable way, you should be puzzled by understanding what a git worktree and how to prepare it. - 0andriy

1 answer 1

When you do a git branch branchname , all the commits that were in the state from which you made the branch automatically fall into the branchname. At this point, your branch and the state from which you made it are identical. If you want within your repository to get a "clean" branch without previous commits (for example, for a task with a code not related to anything already committed), you can do this:

 git checkout firstCommitId -b newBranchname 

where firstCommitId is the first commit number in the repository, and newBranchname is the name of your new branch. In this case, your new branch will contain only the first commit in the repository.