5

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
  • 321
  • 1
  • 3
  • 12

1 Answers1

6

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
  • 448,244
  • 59
  • 642
  • 775