Tim
Tim

Reputation: 99408

Do git pull, fetch, and clone create local and remote tracking branches?

git clone will create a pair of local and remote tracking branches.

git fetch will only create (or update?) the remote tracking branch, and not create a local tracking one, from http://git-scm.com/book/ch3-5.html:

It’s important to note that when you do a fetch that brings down new remote-tracking branches, you don’t automatically have local, editable copies of them. In other words, in this case, you don’t have a new serverfix branch – you only have an origin/serverfix pointer that you can’t modify.

How about git pull? Does git pull create a pair of local and remote tracking branches, or just a remote tracking branch?

Upvotes: 0

Views: 111

Answers (1)

Makoto
Makoto

Reputation: 106389

When you perform git pull, you're generally performing git fetch and git merge, but the main caveat here is that you're not creating any local branches in this manner. The merge only happens with the branch you're currently pulling into.

For instance, if you were on master, and you performed git pull origin other_branch, you would pull in the latest version of other_branch from origin, but then you would also be merging your changes into your master branch. This operation would not create any local branches on your system.

The general way to create a local tracking branch from remote is through the use of git fetch followed by git checkout. If the branch exists already on your remote repository, then simply executing git checkout new_branch will create a local branch that will track the remote branch for you.

Upvotes: 2

Related Questions