John Little
John Little

Reputation: 12439

How do I get the latest version of a branch

I cloned a remote repo, then did git pull. This works. Then I switch to our develop branch (not created by me)

git checkout somebranch/develop

Now I want to pull the latest copy of this branch:

$git status
On branch somebranch/develop
nothing to commit, working tree clean

$git pull

and get:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.

What? I just want it to get the latest version of this branch!

$ git remote -v
origin  https://dev.azure.com/org/proj/_git/proj(fetch)
origin  https://dev.azure.com/org/proj/_git/proj(push)

I also tried this:

git pull origin somebranch/develop

But this gives:

fatal: Couldn't find remote ref somebranch/develop

This makes no sense - I can see it there in the https://dev.azure.com/ portal, and all the other devs are using it.

I simply did clone, switched to a branch, now I want to get the latest version of that branch. I have done no other commands.

Also, when I just did "git pull", it downloaded a load of changes.

If I do "git branch -a" I see :

remotes/origin/somebranch/develop


$ git branch -vv 

gives:

somebranch/develop 7b2abd41b [origin/somebranch/develop: behind 92] V1/V2 SitePageData merge

The question is, how to I pull the latest version of this branch? What is the command or set of commands to get the latest version of a branch which is not master from the azure git repo which has changes from other devs? Or does one ALWAYS have to manually to the upstream tracking thing to ever get the latest version of a branch, in which case why does git checkout not do this for you?

Upvotes: 1

Views: 2753

Answers (2)

Mark Bramnik
Mark Bramnik

Reputation: 42541

It looks like your branch doesn't have "remote counterpart" - a branch that should usually (by default) look like origin/somebranch/develop

You might want to check this assumption first:

git branch -vv | grep somebranch/develop

If it has a remote branch "linked" to it (upstream branch in terms of git), you should see something like

somebranch/develop   <sha1> [origin/somebranch/develop] <last commit message>

Otherwise it looks like:

somebranch/develop   <sha1> <last commit message>

In this case you should "link" the upstream tracking. The question of doing this technically has been already answered Here

Optionally you can run before the actual command

git fetch --all # just to make sure you have an information about this branch

Upvotes: 0

Abey
Abey

Reputation: 121

You need to set upstream tracking:

git branch --set-upstream-to=origin/somebranch/develop somebranch/develop

Upvotes: 1

Related Questions