Question:
I want to upload to github. When I switch ( git checkout
) between the branches that I previously created, then, accordingly, everything in the directory and file tree is updated according to the branch I switched to. Now from the master branch I want to create a new branch ( git branch
) in order to upload a new dz there, 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 only they are visible branches. I thought it was because I made a git pull command and pulled all the changes (maybe I am wrong). And I decided to upload the created branch, from which all the others are visible. Then I went to githab, followed this thread and saw that my very first homework was in it, but it shouldn't be that way. What am I doing wrong?
Answer:
When you make git branch branchname
, then all commits that were in the state from which you made the branch are automatically included in branchname. At this moment, your branch and the state from which you made it are identical. If you want to get a "clean" branch without previous commits within your repository (for example, for a task with code that has nothing to do with what has already been committed), you can do this:
git checkout firstCommitId -b newBranchname
where firstCommitId is the number of the first commit in the repository and newBranchname is the name of your new branch. In this case, your new branch will only contain the first commit in the repository.