0

My git was refusing to create a branch from a remote branch but was error-ing with 'is-it-not-a-commit'as per this issue: Why is it not a commit and a branch cannot be created from it?

But as suggested by @SillyFreak it started working after I ran:

git fetch upstream refs/heads/master:refs/remotes/upstream/My-Remote-Branch-Name

However it only created a local branch (with new name as I prior deleted a error branch) without the tracking attribute.

When I try to add it with Git branch -u upstream/My-Remote-Branch-Name it says fatal: Cannot setup tracking information; starting point 'upstream/My-Remote-Branch-Name' is not a branch.

There are still some gremlins here - not sure what to try next

SystemsInCode
  • 629
  • 7
  • 19
  • 1
    Is it possible to check what that upstream point **is**? Like `git cat-file -p refs/remotes/upstream/My-Remote-Branch-Name`, what does that show you? – Lasse V. Karlsen Oct 27 '20 at 14:57
  • @Lasse V.Karlsen gives: tree someHASH parent someHASH2 parent someHASH3 author Some User 1603796937 +0200 committer GitHub Enterprise 1603796937 +0200 Merge pull request #4385 from other-user/some-other-branch JIRA comment content – SystemsInCode Oct 27 '20 at 15:23
  • 1
    Looks correct, at least we don't have a case of someone resetting a branch name to point to a tag object, for instance. – Lasse V. Karlsen Oct 27 '20 at 15:34
  • The only obvious error I have is I made (prob by using wrong syntax) a branch called upstream recently - but I deleted it. I'm also using the Intellij Idea on OSX and sometimes its GIT command UI is out of sync with the cmdline. – SystemsInCode Oct 27 '20 at 15:36
  • 1
    To create your local branch : did you try `git checkout My-Remote-Branch-Name` ? – LeGEC Oct 27 '20 at 17:33
  • 1
    To check if a branch named "My-Remote-Branch-Name" actually exists in upstream : do you see it mentioned in `git ls-remote upstream` ? – LeGEC Oct 27 '20 at 17:34
  • @LeGEC - Yes (thanks not used this before) shows as : 7eb1eadf5db5e731939feb3746e82974fe037e57 refs/heads/My-Remote-Branch-Name – SystemsInCode Oct 27 '20 at 17:40
  • ok. Now about your local refs : can you add the output of `git for-each-ref | grep My-Remote-Branch-Name` ? – LeGEC Oct 27 '20 at 18:16
  • @LeGEC 7eb1eadf5db5e731939feb3746e82974fe037e57 commit refs/heads/My-Remote-Branch-NameUpstream 7eb1eadf5db5e731939feb3746e82974fe037e57 commit refs/remotes/origin/My-Remote-Branch-Name 7eb1eadf5db5e731939feb3746e82974fe037e57 commit refs/remotes/upstream/My-Remote-Branch-Name Please note I may have run the wrong command to update refs.. see comments to Mark – SystemsInCode Oct 27 '20 at 18:40

1 Answers1

1

git fetch upstream refs/heads/master:refs/remotes/upstream/My-Remote-Branch-Name

I do not think this means what you think it means.

What you've done is to create, locally, something that looks like a remote tracking ref for a remote branch that would be called My-Remote-Branch-Name; but that ref is just pointing to the remote's master (as of the time of this command).

You also have not created a local branch.

git branch -u upstream/My-Remote-Branch-Name

This command is for when the branch already exists on the remote. Based on what you've posted, it looks like it does not.

The first thing it sounds like needs done is to clarify why a branch you believe exists on the remote is not showing up in any of the commands you're running.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • I don't think so I go this from https://git-scm.herokuapp.com/book/ms/v2/Git-Branching-Remote-Branches where it quotes syntax: $ git branch -u origin/serverfix Tried git branch -u upstream My-Remote-Branch-Name and it errors branch 'My-Remote-Branch-Name' does not exist (which it does as it made the local branch ok) – SystemsInCode Oct 27 '20 at 15:32
  • 1
    Ok.... I misread a couple things in the commands you sent. I've updated my answer. – Mark Adelsberger Oct 27 '20 at 15:56
  • The first line in your answer was me trying to fix the non-branch creating step this got past that - but this was me trying something without really understanding git internals and hoping that it worked right. You think I should have run git fetch upstream refs/heads/*My-Remote-Branch-Name*:refs/remotes/upstream/My-Remote-Branch-Name ? I know that the upstream branch does exist as we use it all the time.. – SystemsInCode Oct 27 '20 at 17:33
  • I had the same again today where git reset -hard upstreasm/My-Remote-Branch-Name was not pulling the latest commits - but ran 'git upstream refs/heads/*My-Remote-Branch-Name*:refs/remotes/upstream/My-Remote-Branch-Name and it fixed it. – SystemsInCode Nov 09 '20 at 21:52
  • happend again..not sure how this error can be made to be occur (I'm mainly using intellij ideas git tools) – SystemsInCode Dec 22 '20 at 17:11