A very popular question here on SO is:
How do I check out a remote Git branch?
but the answers there either assume the branch-of-interest is already fetched, or suggest that we git fetch first.
My question: Is it possible to checkout a remote branch which has not yet been fetched, with a single git command?
Note: You may assume as new a version of git as you like, if it matters.
1 Answer 1
If you don't have the branch fetched at all, you could create an alias. In ~/.gitconfig:
[alias]
checkout-with-fetch = "!f() { git fetch origin 1ドル >/dev/null && git checkout -b 1ドル origin/1ドル }; f"
This will run a git fetch, but at least you get the illusion that it didn't... however I wouldn't recommend overwriting git commit as this is bound to cause you to unintentionally lose some work later on.
4 Comments
Explore related questions
See similar questions with these tags.
git fetch+git checkout/switchyet. We can create and checkout a branch withoutgit 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.