I have master branch and dev branch. After some dev branch development I want to make another dev2 branch from dev branch. Should I just use 'git branch' from dev branch and 'checkout dev2' and continue commits?
1 Answers
Yes, you can do it and it is perfectly fine.
When you are on the dev
branch, you can create a new branch in a bunch of ways:
git branch dev2
This just creates a new branch named dev2
from the current branch while not changing to that branch. You can then use git checkout dev2
to check that branch out.
Instead, you can also just directly use
git checkout -b dev2
This would also create a new branch named dev2
from dev
and also check that branch out in the same step.
If you leave out the -b
, it would also work but just check out the branch instead of showing an error if the branch already exists.
If you want to specify what the branch is based of, you can do
git checkout -b dev2 dev
This also creates the new branch dev2
and switches to it but it doesn't create it from your current branch (actuallyHEAD
) but you explicitely stated to create it from dev
.
If you want to revert multiple commits, you can do it as described here:
git revert --no-commit hash-of-first-commit-to-revert~..HEAD
git commit
This reverts all commits from the commit hash you specify until your current HEAD without committing and then creates a single commit.
~
means that you start before the commit you specify so it won't skip that.
..HEAD
means that it reverts all commits **until HEAD and not just the one you specified.

- 12,568
- 8
- 34
- 67
-
And for 'git revert' I use git desktop ,how I should approach that with commands? – Audrius May 05 '21 at 20:20
-
`git revert ` is acommand that just creates a new commit reverting the changes of another commit. What did you ask about it? – dan1st May 05 '21 at 20:22
-
what would be command to undo all commits to the certain commit? – Audrius May 05 '21 at 21:32
-
Do you want to remove those commits (not recommended), create a commit that undoes them or create a branch with that old state? – dan1st May 06 '21 at 04:34
-
create commit that undoes them until certain commit – Audrius May 06 '21 at 12:28
-
I have added this to my answer. – dan1st May 06 '21 at 12:49