0

I recently cloned a repo from remote onto a new machine. The remote has 2 branches master & dev. After cloning, local has only remote's master branch, no dev found.

On remote, dev has merged with master and master is like 2 commits ahead of dev.

Locally if I create a new branch of the same name dev, dev now points to tip (same commit) of master in contrast to remote where dev is like 2 commits behind master.

How to get all remote branches locally, correctly pointing to their respective commits as on remote.

Moreover, out of curiosity, just checking out the .git directory and found this line in config under .git directory.

Can someone explain what does the following line mean fetch = +refs/heads/*:refs/remotes/origin/* in .git/config? In particular the role of colon : separator.

thanks dk

dkjain
  • 717
  • 1
  • 7
  • 31
  • Possible duplicate of [How to fetch all git branches](https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches) – phd Oct 08 '17 at 16:23

1 Answers1

0

I think all you need to do here is a git fetch:

git fetch origin

This will bring in all remote branches to your local repository in the form of remote tracking branches. This should include both the remote master and dev branches. Note that your initial clone should have already brought in these branches. But doing a git fetch will update dev with the latest information and this is a reasonable thing to do.

If you want to create a local dev branch which tracks the remote one, you can do this:

git checkout dev

This will create a new local branch dev which tracks the remote one.

Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263
  • even without `git fetch origin` if i run `git checkout dev`, git tells `Switched to new branch `dev`. Branch dev set up to track remote branch dev from origin.` so what's the point/advantage of `git fetch origin`. thanks – dkjain Oct 08 '17 at 16:32
  • 1
    @dkjain The clone you did, in general, may or may not have captured all remote branches. Doing a `git fetch` guarantees that you will have `dev` locally. – Tim Biegeleisen Oct 08 '17 at 16:44