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.)
Asked
Active
Viewed 251 times
-3
-
3Well how are you using git under Windows? Through PowerShell, Cygwin, or some GUI client? – Will Feb 13 '16 at 18:01
-
1What do you mean by "create a new branch"? Exactly what did you type or click? – michas Feb 13 '16 at 18:04
-
1Please see http://stackoverflow.com/help/how-to-ask. – jub0bs Feb 13 '16 at 18:12
2 Answers
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
-
-
@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