Pregunta

I need to check-out one branch at a time (may be another at different time). To make it fastest I am doing below steps.

  1. git remote add -f origin <Repository address> (at first time only)

and on subsequent fetches for a particular branch

  1. git checkout -b branch localbranch

Do we have anything else to make this approach faster? I am more interested in fastening the first step.

¿Fue útil?

Solución

I'm not sure I understand your use case here, because you can't "check out" a particular folder in a repository. In fact, your checkout command will result in an error:

$ git checkout -b branch DestinationFolder
fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'dir1' which can not be resolved as commit?

If you want to clone a remote repository and set it to a particular branch in a single step, you can use the -b flag to the clone command:

$ git clone -b branch git://git.example.com/myrepository

This will have the side effect of also setting up a remote named origin pointing at the remote repository.

Otros consejos

You can use an alias:

[alias]
    fastcheckout = !sh -c 'git remote add -f \"$1\"; git checkout -b \"$2\" \"$3\"' -

Usage:

git fastcheckout <remote> <branch-name> <start-point>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top