Skip to main content
Stack Overflow
  1. About
  2. For Teams

Timeline for Can I checkout an unfetched remote git branch, with a single command?

Current License: CC BY-SA 4.0

Post Revisions

21 events
when toggle format what by license comment
Dec 19, 2024 at 11:44 comment added einpoklum @Guildenstern: You mean the two-command alias? Ok, what about it?
Dec 19, 2024 at 7:33 comment added Guildenstern The same command as in the only answer so far
Dec 18, 2024 at 21:49 comment added einpoklum @Guildenstern: "The one" what? I'm not following.
Dec 18, 2024 at 21:42 comment added Guildenstern @einpoklum The one provided in the only answer so far, which you criticized as not really being a single command, but nonetheless a "decent hack I suppose".
Dec 18, 2024 at 21:29 comment added einpoklum @Guildenstern: This would be exactly the same as if you had run something like git fetch origin mian; git checkout origin/mian.
Dec 18, 2024 at 18:09 comment added Guildenstern @einpoklum I wouldn’t expect Git to ever do a network call on git-checkout(1) just-in-case there was something on some remote unless I’m working in a shallow checkout or other such on-demand modes.
Dec 18, 2024 at 16:06 comment added einpoklum @Guildenstern: Yes, exactly. Just like if you were to mistype mian instead of main if you did that using two commands...
Dec 18, 2024 at 14:24 comment added Guildenstern @einpoklum " it will interpret my request as also indicating it should fetch..." Meaning that git-checkout(1) would do a fetch to check if mian is in origin now when I misstype main?
Dec 18, 2024 at 10:20 comment added einpoklum @ElpieKay: I'm not sure how I could further explain my initial motivation... it seems intuitive to me that if I tell git about a remote branch that I want to checkout, and it does not yet know about that branch, it will interpret my request as also indicating it should fetch information about that branch from the remote.
Dec 18, 2024 at 10:14 comment added ElpieKay @einpoklum So far as I know, there is no shortcut command that combines git fetch + git checkout/switch yet. We can create and checkout a branch without git fetch, but the branch may not point at the right commit. I asked because I want to know your initial motivation to this question. You may think a single command could solve your problem. I want to make it clear and maybe find another solution.
Dec 18, 2024 at 9:57 comment added Ali Raza Sorry, I thought that was already established. It is not possible, there is no way of doing this.
Dec 18, 2024 at 9:52 comment added einpoklum @AliRaza: "no its not" <- perhaps you should read the rest of my sentence. "Git operates on local knowledge of remote branches" <- I'm giving it the knowledge it needs, which is: the name of a branch on the remote. It does not need further knowledge in order to fetch that branch and check it out. Anyway, if you're certain git won't do that, then write an answer saying "No, it's not possible". It's as good an answer as any, if that's actually the case.
Dec 18, 2024 at 9:49 comment added Ali Raza Agree with Romain here. You are asserting statements that aren't correct and trying to pass opinions as facts. "Because its a signle command" no its not. Git operates on local knowledge of remote branches. Checking out a remote branch requires two operations, one to fetch the reference and another to switch to the branch. Your opinion that this should be a single command is irrelevant when discussing git because that's not how git is implemented
Dec 18, 2024 at 9:49 comment added Romain Valeri Atomic commands are useful, and composite commands are also useful. But ignoring the underlying steps doesn't magically make them unexist. If your local machine needs to display some data, this data has to come accross the network at some point, in some way. If you're asking if there's a composite command to combine fetching and checking out, I don't find that absurd at all, yes it could be useful, but no it doesn't exist as such. Aliases are here to do this sort of small command grouping.
Dec 18, 2024 at 9:47 comment added einpoklum @RomainValeri: By your logic, we shouldn't have a command for creating a branch and switching to it, either. "Why is it a problem" to first create the branch, then switch to it?
Dec 18, 2024 at 9:46 comment added Romain Valeri Your explanation about it being a single step "in english" is technically irrelevant. Compare with someone asking "Please write function X to add two variables". There is no information that I need to type characters, so my IDE shouldn't need it either. (Not trying to be the snark knight here, just desperately trying to understand your odd question setting)
Dec 18, 2024 at 9:42 comment added Romain Valeri Your "no fetch" constraint seems arbitrary. Why is it a problem? How do you expect your machine to read distant data without said data being transported over network at some point? Are you searching for alternatives to git protocol?
Dec 18, 2024 at 9:32 answer added Josh Brunton timeline score: 0
Dec 18, 2024 at 9:32 comment added einpoklum Because it is a single command - in English: "Please check out branch foo from remote bar". There is no information that I need from the fetch, so git shouldn't need it either before taking that command from me.
Dec 18, 2024 at 9:28 comment added ElpieKay Why would you like it as a single git command?
Dec 18, 2024 at 9:17 history asked einpoklum CC BY-SA 4.0
toggle format

AltStyle によって変換されたページ (->オリジナル) /