Square-root Square-root - 2 months ago 6
Git Question

Is there a way to bring remote branches to local using pull?

Just want to double check a few things here:

1) So git pull --rebase will pull changes from the remote master but it will not pull any remote branches, right? I tried to do this and the remote branch didn't appear in my local list of branches as I thought it will bring everything from the remote site.

2) To pull remote branches to work on them locally I should use fetch followed by checkout, right?

3) Is there a way to pull remote branches locally using pull?

Answer

1) ... it will not pull any remote branches, right?

Aside from the one checked out, correct, but it will fetch all the remote's branches as tracking branches <remote>/<branch> e.g. origin/master and then merge the local branch you currently have checked out with the remote branch you have setup to track, either explicitly or by default.

You can see a full list of local and tracking branches with:

git branch -avv

2) To pull remote branches to work on them locally I should use fetch followed by checkout, right?

Yes if you do not have a local branch yet, then checkout will create it. However, if you do have one, then you'll need to merge (or pull) after checkout

3) Is there a way to pull remote branches locally using pull?

Yes, the easiest way I can think of is to create an alias that will checkout all the branches, but you really don't want to do this in my opinion. There's no real advantage to eager loading all the local branches, so just check them out when you're actually ready to work on them.

Comments