Thread (16 messages) flat view 16 messages, 5 authors, 2016-06-15

Re: git branch --switch?

From: Brian Gernhardt <hidden>
Date: 2016-06-15 22:43:05

On Apr 17, 2007, at 9:36 AM, Rene Herman wrote:
Is it possible to switch the current branch without checking it  
out? Not really essential, but I'm happily flaundering around with  
git and still start from scratch fairly regularly; to speed this up  
I've found the -n switch to git clone useful and would like  
something similar when reconstructing my "branch hierarchies".

Upto now I only know about "git checkout" (with or without -b) to  
switch the current branch. As said it's not really essential, but I  
was expecting there would be something like a "branch --switch".  
Did I overlook it?
Perusing git-checkout points me to git-symbolic-ref to update the  
HEAD ref to a new branch:

git symbolic-ref HEAD refs/heads/<branch>

However, I'm somewhat confused as to why you'd want HEAD and the  
working directory to get out of sync.  It would cause any further  
commits to have broken history information.  If you want to make the  
content of one branch ($branchA) the same as the other ($branchB),  
you should do something like:

git checkout -b temp $branchB    # Get content from branchB
git merge -s ours $branchA       # Merge history (not content) from  
branchA
git branch -M $branchA           # Make this new merge branchA

This would be significantly simpler if there was a "theirs" merge  
strategy "git checkout $branchA; git merge -s theirs $branchB", but  
there isn't.  Should be simple to write if you really need it though.

~~ Brian
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help