1

I am getting frustrated because I have a friend that is telling me the app of a certain branch off Bitbucket is working a certain way for him. I had a newer release.

So I decided to do:

git checkout -b release/3.5.1

and

git pull origin release/3.5.1

and I got this response:

 * branch              release/3.5.1 -> FETCH_HEAD
Already up to date.

I have never pulled this branch before, how can it be up to date?

isherwood
  • 58,414
  • 16
  • 114
  • 157
Daniel
  • 14,004
  • 16
  • 96
  • 156

2 Answers2

1

You shouldn't be creating a new branch (with the -b flag). Instead of doing so, just checkout the branch from origin:

git checkout origin/release/3.5.1

If that results in a pathspec (branch not found) error, first do git fetch to retrieve the remote branch references.

Doing a pull as you did results in the remote branch being merged into the local branch only if there was a tracking arrangement created. In this case, there wasn't. You could set it up that way manually when you create the branch:

--track origin/release/3.5.1

That's really more work than necessary, though.

isherwood
  • 58,414
  • 16
  • 114
  • 157
  • If I don't use the `-b` flag and just `git checkout origin/release/3.5.1` and if that results in a pathspec do, I do a `git fetch release/3.5.1`? – Daniel May 28 '19 at 19:20
  • No. Fetch just gets the list. You then do the checkout. – isherwood May 28 '19 at 19:22
  • I asked because I actually tried that before and it did not get me a list of all the branches, thats why I started to do it the way I described above. – Daniel May 28 '19 at 19:37
  • It won't report branches that you have already fetched, just new and updated ones. – isherwood May 28 '19 at 19:43
  • there are plenty of branches with this project that I have never fetched before, most branches I will probably not even need, but `git fetch` does not grab any of them. – Daniel May 28 '19 at 19:49
  • It's starting to sound like your origin config is faulty. – isherwood May 28 '19 at 19:49
1

Just doing git checkout release/3.5.1 would do the trick if you are using git >= 1.6.6

  • "git checkout frotz" when there is no local branch "frotz" but there is only one remote tracking branch "frotz" is taken as a request to start the named branch at the corresponding remote tracking branch.

So this will:

  1. create a new local branch at the start of the remote branch
  2. set it to follow the remote branch

Taken from this original answer.


NOTE: isherwood's answer git checkout origin/release/3.5.1 idea should be better if you don't want to keep a branch locally.

isherwood
  • 58,414
  • 16
  • 114
  • 157
Ulysse BN
  • 10,116
  • 7
  • 54
  • 82