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

1 Answer 1

2

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> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.