0

I am learning git from book, but I struggle with some problems. I have to manually clone jquery repo. Below there are my commands.

git init 
git remote add origin https://github.com/jquery/jquery.git
git fetch --no-tags origin main:refs/remotes/origin/main

I don't fully understand if it that fetch command is correct. jQuery has branch main, but after that I type following command:

git branch --set-upstream-to master origin/main

I get the following error:

fatal: branch 'origin/main' does not exist.

I don't understand why is that. How to set upstream from my local master branch to the main branch in the remote repo of jQuery?

My git version: git version 2.35.1.windows.2

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
dunlop
  • 61
  • 3
  • 1
    **I have to manually clone jquery repo** -- if you clone a repo, its easier to use [git clone](https://git-scm.com/docs/git-clone). also, what version git are you using? depending on the version, the syntax for upstream might be a little different, see [qa](https://stackoverflow.com/a/2286030) it may interest you - specifically the order of the branches. – Bagus Tesa Apr 16 '22 at 15:17
  • I know that it is easier to use clone, but I try to understand that upstream and feel better how git works and I really don't know what is wrong with what I have done and why I can't set upstream that way. Basically I don't get it why git says that origin/main does not exist – dunlop Apr 16 '22 at 15:35
  • Why do you want to set upstream at all? I basically never do. Also, why on earth would you set up a correspondence between local master and remote main? I mean, sure, you can, but you can do a lot of silly things. Just name your local branch main and make life easy. – matt Apr 16 '22 at 21:55

1 Answers1

1

git branch --set-upstream-to master origin/main

Wrong way 'round, and --set-upstream-to is for modifying an existing branch.

git branch -t master origin/main

aka

git branch --track master origin/main

and better might be

git checkout -b master origin/main

Easiest is just use upstream's name and git checkout main, Git will see the unadorned branch name and fire off its convenience checking. There's no main branch yet, so it'll look for a unique remote-tracking branch for it and find the one you set up.

$ git checkout main
branch 'main' set up to track 'origin/main'.
Switched to a new branch 'main'
jthill
  • 55,082
  • 5
  • 77
  • 137