1

When running the git pull command to pull master:

$ git pull ds master

(Note: ds is the remote repo's alias.)

it pops up the following error:

fatal: couldn't find remote ref master

But as running 'git pull' for a branch 'v1', it works.

$ git pull ds v1
From https://github.com/<UserName>/<Repo's name>
 * branch            v1         -> FETCH_HEAD
Already up to date.

I'm wondering if this is the case issue, but it isn't because I run the following command to confirm it:

$ git branch -a
  master
* v1
  remotes/ds/v1

What's the problem? Thanks!

Blue Sea
  • 123
  • 1
  • 10
  • what do you mean by `ds master` ? – Tasnuva Nov 01 '20 at 05:21
  • Please check the note: ds is the remote repo's alias. – Blue Sea Nov 01 '20 at 05:23
  • 'ds' is just 'origin'. – Blue Sea Nov 01 '20 at 05:25
  • oh thanks i didn't notice may be. – Tasnuva Nov 01 '20 at 05:26
  • Does the remote have a branch named `master`? Check in Github or do the command `git ls-remote --heads ds` – Jeff Mercado Nov 01 '20 at 07:07
  • Sorry I'm a bit confused. Isn't master a default branch which exists at the beginning without any more specification? This is the output of the command you recommended: bb986c95d06cdff5192f59ba84e243214c8d97c9 refs/heads/v1 – Blue Sea Nov 01 '20 at 07:10
  • `master` is the default name of the initial branch when you first create a repo. It's not created until you make that initial commit. Apparently the repo doesn't have a `master` but rather a `v1` branch. – Jeff Mercado Nov 01 '20 at 07:15
  • Do you mean that before creating the branch v1, the master branch has existed? And after creating the branch v1, the master branch disppears? Sorry I'm more confused now. – Blue Sea Nov 01 '20 at 07:20

1 Answers1

5

The problem in this case is that your remote ds does not have a branch named master. Probably they've switched to using main instead, but perhaps they just don't have either one. Note that there is nothing special about either name, except that people tend to use those as the initial name of the first branch they create. Any branch can be renamed at any time: the names are not significant.

Note that in Git, a branch name merely holds the hash ID of the last commit that Git should consider to be part of the branch. The two constraints on branch names are:

This means that in a new, empty Git repository, with no commits in it, no branch names exist. Nonetheless, you are, in such a repository, "on" some branch. You're just on a branch that doesn't exist. Making the first commit creates the branch with that name—so until you make the first commit, you can change the name as much as you like: you're changing the name of the branch that doesn't exist.

Yesterday, upon the stair,
I met a man who wasn't there!
He wasn't there again today.
Oh how I wish he'd go away!
—William Hughes Mearns

Once you've created your first commit, your initial branch name now exists. You may now rename it, and/or create as many more branch names as you like, though all must select this same commit. As you add more commits to the repository, you can make the various branch names point to different commits, and/or add new branch names. The existing commits remain, and are findable—or not findable—by starting from some named commit and working backwards.

torek
  • 389,216
  • 48
  • 524
  • 664