Reputation: 132128
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.
Upvotes: 0
Views: 83
Reputation: 527
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.
Upvotes: 0