Created a new branch, but it contains all the commits from master. How to remove all these commits?
- Counter question: why remove them? What do you want to get in the end, what problem do you solve? - Nick Volynkin ♦
2 answers
A branch (branch) in git is just a (floating) pointer to a commit.
creating a new branch, you (by default) just duplicate the pointer - it will point to the same commit as the current branch.
when creating a branch, i.e., a new pointer, you can immediately specify which commit it will indicate:
$ git branch имя-новой-ветки стартовая-точка
or (create and immediately switch to a new branch):
$ git checkout -b имя-новой-ветки стартовая-точка
moreover - you can “move” the already created pointer:
$ git branch -f имя-существующей-ветки новая-стартовая-точка
and if it is “very necessary” (leaving the framework for the expediency of such a move and the integrity of the repository), then you can create a branch from scratch. those. The first commit you make to it will not have “ancestors”. for this is the option - --orphan
checkout
command:
$ git checkout --orphan имя-новой-ветки
Branches to git is a way to develop something in parallel, with the ability to merge your changes into the main branch.
If you need a branch without history, it means that you need not a branch anymore, but just a separate repository.