{"thread":{"id":"58903","subject":"bug report: git push fails in worktree","startedAt":"2022-12-06T01:14:02Z","lastAt":"2022-12-06T11:24:37Z","messageCount":3,"participants":["tionis","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"468570","messageId":"COUBW3AG192J.1UCDLVUZ38VJA@tempest","threadId":"58903","inReplyTo":null,"subject":"bug report: git push fails in worktree","fromName":"tionis","fromEmail":"out@tionis.dev","sentAt":"2022-12-06T01:03:14Z","receivedAt":"2022-12-06T01:14:02Z","isPatch":false,"sender":{"key":"out@tionis.dev","avatar":null},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\nSetup two branches.  \nCheck the main one out in a repo.  \nCheckout the second one using a worktree with\ngit worktree add ~/some/path branch-name\nAdd commits in ~/some/path\ngit status shows:\nOn branch dev\nYour branch is ahead of 'dev/main' by 1 commit.\n  (use \"git push\" to publish your local commits)\nExecute git push\n\nWhat did you expect to happen? (Expected behavior)\nexpected the one commit to be pushed\n\nWhat happened instead? (Actual behavior)\nthe command only returns \nEverything up-to-date\nand nothing is pushed\n\nWhat's different between what you expected and what actually happened?\ngit should detect the commits to push correctly\n\nAnything else you want to add:\nthis was mentionend before on stack overflow:\nhttps://stackoverflow.com/questions/41158057/why-does-git-allow-pushing-to-a-checked-out-branch-in-an-added-worktree-how-sha\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n[System Info]\ngit version:\ngit version 2.38.1\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 5.15.80-1-MANJARO #1 SMP PREEMPT Sat Nov 26 13:41:30 UTC 2022 x86_64\ncompiler info: gnuc: 12.2\nlibc info: glibc: 2.36\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\npost-checkout\npost-commit\npost-merge\npre-push\n"},{"id":"468575","messageId":"xmqqr0xdnw88.fsf@gitster.g","threadId":"58903","inReplyTo":"COUBW3AG192J.1UCDLVUZ38VJA@tempest","subject":"Re: bug report: git push fails in worktree","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-12-06T01:42:47Z","receivedAt":"2022-12-06T01:42:52Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"tionis\" <out@tionis.dev> writes:\n\n> Thank you for filling out a Git bug report!\n> Please answer the following questions to help us understand your issue.\n>\n> What did you do before the bug happened? (Steps to reproduce your issue)\n> Setup two branches.  \n> Check the main one out in a repo.  \n> Checkout the second one using a worktree with\n> ...\n> Execute git push\n\nThere must be some steps missing still in the above description.\nYou seem to be expecting \"git push\" to push things out to\nsomewhere, but in the above sequence (I am assuming that you started\nwith \"git init\" to create a local repository), there is nothing I\nsee that tells \"git push\" where to push to.  There must have been\nsome step not described above that sets configuration to tell where\nto push what when \"git push\" is run without \"where to\" and \"what\"\non the command line.\n\nWell, I am assuming too much.  Your \"Execute git push\" may not mean\n\"type g i t SPACE p u s h RETURN and do nothing else\" (it may mean\n\"run 'git push https://github.com/tionis/sample <RETURN>'\", for\nexample, and readers cannot tell).\n\nIf you didn't use an extra worktree, but otherwise do the same\nthing, does \"git\" push out what you expect it to?\n\n"},{"id":"468618","messageId":"COUP3909LNS6.YZG9S8YIV3SQ@tempest","threadId":"58903","inReplyTo":"xmqqr0xdnw88.fsf@gitster.g","subject":"Re: bug report: git push fails in worktree","fromName":"tionis","fromEmail":"out@tionis.dev","sentAt":"2022-12-06T11:23:49Z","receivedAt":"2022-12-06T11:24:37Z","isPatch":false,"sender":{"key":"out@tionis.dev","avatar":null},"body":"Sorry, you're right I totally forgot some steps. \nI tried to reproduce the error in a Docker Container using the\nDockerfile below:\n\nFROM alpine:latest\nRUN apk add git\nRUN git clone https://tasadar.net/tionis/test.git /root/test\nWORKDIR /root/test\nRUN git remote add other-test https://tasadar.net/tionis/other-test.git\nRUN git fetch other-test main:other-test\nRUN git branch --set-upstream-to=other-test/main other-test\nRUN git worktree add /root/other-test other-test\nWORKDIR /root/other-test\nRUN touch this-is-a-test-file\nRUN git config --global user.email \"person@example.com\"\nRUN git config --global user.name \"Name\"\nRUN git add .\nRUN git commit -m \"commit this-is-a-test-file\"\nCMD [\"sh\"]\n\nThis time git showed me following error message when trying to push:\n\nfatal: The upstream branch of your current branch does not match\nthe name of your current branch.  To push to the upstream branch\non the remote, use\n\n    git push other-test HEAD:main\n\nTo push to the branch of the same name on the remote, use\n\n    git push other-test HEAD\n\nTo choose either option permanently, see push.default in 'git help config'.\n\nFollowing this reference I could resolve my issue by changing the config\nusing: \ngit config push.default upstream\n\nI'm sorry to have wasted your time with this and wish you a nice day.\n"}]}