git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git branch --switch?

From
Brian Gernhardt <benji@silverinsanity.com>
Date
Apr 17, 2007, 14:31 UTC
Message-ID
<C940520E-732A-4F6E-A7F2-0215FD534455@silverinsanity.com>
In-Reply-To
<4624CD58.90103@gmail.com>
On Apr 17, 2007, at 9:36 AM, Rene Herman wrote:
Show 10 quoted lines
> 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
Previous: Rene HermanNext: Rene Herman
Message 7 of 18 in “git branch --switch?”
  1. Rene HermanApr 17, 2007
  2. Alex RiesenApr 17, 2007
  3. Rene HermanApr 17, 2007
  4. Brian GernhardtApr 17, 2007
  5. Alex RiesenApr 17, 2007
  6. Rene HermanApr 17, 2007
  7. Brian GernhardtApr 17, 2007
  8. Rene HermanApr 17, 2007
  9. Rene HermanApr 17, 2007
  10. Lars HjemliApr 17, 2007
  11. Rene HermanApr 17, 2007
  12. Randal L. SchwartzApr 17, 2007
  13. Rene HermanApr 17, 2007
  14. Lars HjemliApr 17, 2007
  15. Rene HermanApr 17, 2007
  16. Rene HermanApr 17, 2007
  17. Linus TorvaldsApr 17, 2007
  18. Rene HermanApr 17, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.