Carl
Carl

Reputation: 44488

Git: Is there a short way to setup a new branch to track a remote branch?

The usual command is:

git checkout origin/branch_i_want -b branch_i_want

Git responds with:

Branch branch_i_want setup to track remote branch branch_i_want from origin.

This is fine.

My question is simple. Most of the time, the locally created branch has the same name as the remote branch. Is there a git command that does this so I do not need to type the branch name twice?

In other words, is there something like:

git checkout --autocreate-tracking origin/branch_i_want

Which would, in theory create a local branch named branch_i_want and set it up to track origin/branch_i_want ?

Upvotes: 2

Views: 258

Answers (1)

hobbs
hobbs

Reputation: 240404

With recent git (I think >= 1.7) you can just do git checkout -t remotename/branchname, and -b branchame is implied.

Upvotes: 5

Related Questions