1

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 enter image description here

Is there any short equivalent command in Git ? Thanks a lot

BCPeng
  • 163
  • 1
  • 10

1 Answers1

1

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>
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250