0

Added:

fetch issue was due to me not understanding how clone --mirror works, see my answer below.

Original:

I did search. tried to read Git pull after forced update, git refusing to fetch into current branch, How can I recover a lost commit in Git? but still cannot understand my situation.

Both local and remote on main branch currently (by git status). git log on both confirmed local is ahead of remote by 2 commits. Why git fetch apparently tries to update HEAD?

git fetch
fatal: Refusing to fetch into current branch refs/heads/master of non-bare repository
fatal: The remote end hung up unexpectedly

git pull did force update and my main "lost" recent commits. From linked post I've read to do git reflog and rest --hard to last commit and I'm back to square one.

Also currently I face another issue (as initially seeing local is ahead I wanted to push) I've just posted as names match, but: "The upstream branch of your current branch does not match the name of your current branch", git pull wrote "forced update"":

git push outputs "The upstream branch of your current branch does not match the name of your current branch".

What happened to the repo? Why git pull does force update by default w/out asking? Why git push does not find remote branch?

Added:

I continue see some more interesting things, still w/out understanding why git does not see match of main branches, I did git push origin HEAD:refs/remotes/origin/main and saw push succeeded:

Total x (delta y)
To remote_url 
ref_of_last_remote_commit...ref_of_last_local_commit HEAD -> origin/head

But: git reflog on remote did not output those new commits!

Martian2020
  • 307
  • 3
  • 12

2 Answers2

2

It’s hard to exactly understand what has gone wrong without knowing the context of your problem (i.e. the status of your git repository), but you said “ git push outputs ‘The upstream branch of your current branch does not match the name of your current branch’.” and that could be a clue.

Assuming your local branch is named main and your remote repository is named origin (you can verify this by git remote -v), the common setup is that your local branch main should be tracking remote branch origin/main. Check by typing git branch -vv. If they don’t match, try using git push -u origin main to make your remote branch name match with that of your local’s.

Or if origin/main already exists, you can try rename your local branch to some unique name (git checkout -b <the_unique_name> after you have committed everything locally) and do git push -u origin <the_unique_name>.

fjs
  • 330
  • 2
  • 9
0

I've made that repo with git clone --mirror, now with help of @torek in Why line with "fetch" in git config effects how `git branch --set-upstream-to` work? I understand it was root cause of results/issues as --mirror sets in .git/config : fetch = +refs/*:refs/* (which I left as it was, but I've changed core.bare=false).

  1. fetch refused as I asked it to update all refs, including current branch.
  2. With fetch set for mirroring, git pull is expected to update all local refs with ones from remote, hence forced update
Martian2020
  • 307
  • 3
  • 12