Reputation: 163
Is there anyone knows how to
checkout a local branch from a remote's one with the same name with more convenient command?
I usually do it by typing remote branch's name in param manually
Ex: git checkout -b remotebranchName origin/remotebranchName
Or do it in Android Studio by
Check out as a new remote branch
Is there any short equivalent command in Git ? Thanks a lot
Upvotes: 1
Views: 1230
Reputation: 1324218
Yes the short version is:
git checkout remotebranchName
As mentioned in the manual:
If
<branch>
is not found but there does exist a tracking branch in exactly one remote (call it<remote>
) with a matching name, treat as equivalent to:
git checkout -b <branch> --track <remote>/<branch>
With Git 2.23+, the new command git switch
would also create the branch and track its upstream branch in one line:
git switch remotebranchName
If
<branch>
is not found but there does exist a tracking branch in exactly one remote (call it<remote>
) with a matching name, treat as equivalent to:$ git switch -c <branch> --track <remote>/<branch>
Upvotes: 2