threads / bug / 58903

bug report: git push fails in worktree

Subject: bug report: git push fails in worktree

## tl;dr

3 messages between Dec 6, 2022 and Dec 6, 2022.

replies: 2people: 2as markdown or json

tionis· Dec 6, 2022, 01:03 UTC · lore

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
Setup two branches.  
Check the main one out in a repo.  
Checkout the second one using a worktree with
git worktree add ~/some/path branch-name
Add commits in ~/some/path
git status shows:
On branch dev
Your branch is ahead of 'dev/main' by 1 commit.
  (use "git push" to publish your local commits)
Execute git push

What did you expect to happen? (Expected behavior) expected the one commit to be pushed

What happened instead? (Actual behavior) the command only returns Everything up-to-date and nothing is pushed

What's different between what you expected and what actually happened? git should detect the commits to push correctly

Anything else you want to add: this was mentionend before on stack overflow: https://stackoverflow.com/questions/41158057/why-does-git-allow-pushing-to-a-checked-out-branch-in-an-added-worktree-how-sha

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.38.1 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.15.80-1-MANJARO #1 SMP PREEMPT Sat Nov 26 13:41:30 UTC 2022 x86_64 compiler info: gnuc: 12.2 libc info: glibc: 2.36 $SHELL (typically, interactive shell): /bin/bash

[Enabled Hooks] post-checkout post-commit post-merge pre-push

Junio C Hamano· Dec 6, 2022, 01:42 UTC · re: tionis · lore

Re: bug report: git push fails in worktree

"tionis" <out@tionis.dev> writes:
Show 9 quoted lines
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
>
> What did you do before the bug happened? (Steps to reproduce your issue)
> Setup two branches.  
> Check the main one out in a repo.  
> Checkout the second one using a worktree with
> ...
> Execute git push

There must be some steps missing still in the above description. You seem to be expecting "git push" to push things out to somewhere, but in the above sequence (I am assuming that you started with "git init" to create a local repository), there is nothing I see that tells "git push" where to push to. There must have been some step not described above that sets configuration to tell where to push what when "git push" is run without "where to" and "what" on the command line.

Well, I am assuming too much. Your "Execute git push" may not mean "type g i t SPACE p u s h RETURN and do nothing else" (it may mean "run 'git push https://github.com/tionis/sample <RETURN>'", for example, and readers cannot tell).

If you didn't use an extra worktree, but otherwise do the same thing, does "git" push out what you expect it to?

tionis· Dec 6, 2022, 11:23 UTC · re: Junio C Hamano · lore

Re: bug report: git push fails in worktree

Sorry, you're right I totally forgot some steps. I tried to reproduce the error in a Docker Container using the Dockerfile below:

FROM alpine:latest RUN apk add git RUN git clone https://tasadar.net/tionis/test.git /root/test WORKDIR /root/test RUN git remote add other-test https://tasadar.net/tionis/other-test.git RUN git fetch other-test main:other-test RUN git branch --set-upstream-to=other-test/main other-test RUN git worktree add /root/other-test other-test WORKDIR /root/other-test RUN touch this-is-a-test-file RUN git config --global user.email "person@example.com" RUN git config --global user.name "Name" RUN git add . RUN git commit -m "commit this-is-a-test-file" CMD ["sh"]

This time git showed me following error message when trying to push:

fatal: The upstream branch of your current branch does not match the name of your current branch. To push to the upstream branch on the remote, use

    git push other-test HEAD:main
To push to the branch of the same name on the remote, use
    git push other-test HEAD
To choose either option permanently, see push.default in 'git help config'.

Following this reference I could resolve my issue by changing the config using: git config push.default upstream

I'm sorry to have wasted your time with this and wish you a nice day.

← back to recent threads