0

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?

Audrius
  • 33
  • 2
  • 8

1 Answers1

2

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.

dan1st
  • 12,568
  • 8
  • 34
  • 67