-3

I noticed that, on Windows, when I create a new branch in my repository using the shell, Git doesn't change the branch I am on. When using Linux, it does. How's that? Is there a possibility to change that, to the way Git in Linux does? (I'm very new to Git.)

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Hüftl
  • 211
  • 2
  • 12

2 Answers2

2

To create a new branch and switch to it at the same time, use git checkout -b <branchname>.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
  • Thanks a lot. That was my Problem. Didn't use -b. – Hüftl Feb 13 '16 at 18:58
  • @AlexM. This command has the same effect in all versions of Git, irrespective of the platform. What your actual problem was is unclear. – jub0bs Feb 13 '16 at 19:12
  • Maybe I'm mistaking, but as I used the checkout command without "-b" in Linux it changed the branch automatically – Hüftl Feb 13 '16 at 19:30
0

I noticed that, on Windows, when I create a new branch in my repository using the shell, Git doesn't change the branch I am on

The commands for branching are the following:

# create branch and stay on the current branch
git branch <branch name>

# create a branch and switch to the new branch
git checkout -b <branch name>

# You can always create branch from any given commit/tag/branch etc you need
git checkout -b <SHA-1>/tag/branch

You can find in this answer a very useful information what it does and how to do it:

How to move HEAD back to a previous location? (Detached head)

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Thanks for pointing this out. As ou can see, without -b it stays on the current branch. That was my problem. – Hüftl Mar 13 '16 at 15:02