{"thread":{"id":"49221","subject":"Get \"Your branch is ahead of 'origin/master'\" message when explicitly passing origin url at push command","startedAt":"2018-08-26T11:47:54Z","lastAt":"2018-08-27T15:19:46Z","messageCount":3,"participants":["Bentzy Sagiv","Bryan Turner"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"356560","messageId":"MWHPR10MB1517982C582BEFB7D9171EFD9B340@MWHPR10MB1517.namprd10.prod.outlook.com","threadId":"49221","inReplyTo":null,"subject":"Get \"Your branch is ahead of 'origin/master'\" message when explicitly passing origin url at push command","fromName":"Bentzy Sagiv","fromEmail":"bentzy.sagiv@firemon.com","sentAt":"2018-08-26T11:37:52Z","receivedAt":"2018-08-26T11:47:54Z","isPatch":false,"sender":{"key":"bentzy.sagiv@firemon.com","avatar":null},"body":"git version 2.7.4\n______________________________________________________________________________________________________\n\nFirst try: NOT passing origin url explicitly\n\nubuntu@ci-bentzy:/var/lib/jenkins$ git remote -v\norigin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (fetch)\norigin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (push)\n\nubuntu@ci-bentzy:/var/lib/jenkins$ sudo vim jobs/bentzytest1/config.xml\nubuntu@ci-bentzy:/var/lib/jenkins$ sudo git add .\nubuntu@ci-bentzy:/var/lib/jenkins$ sudo git commit -m'First try' -a\n[master b8549c3] First try\n 1 file changed, 2 insertions(+), 2 deletions(-)\n \nubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push\nPassword for 'https://USER @ bitbucket.org':\nCounting objects: 5, done.\nDelta compression using up to 2 threads.\nCompressing objects: 100% (4/4), done.\nWriting objects: 100% (5/5), 399 bytes | 0 bytes/s, done.\nTotal 5 (delta 3), reused 0 (delta 0)\nTo https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git\n   d2cc229..b8549c3  master -> master\n  \nubuntu@ci-bentzy:/var/lib/jenkins$ git status\nOn branch master\nYour branch is up-to-date with 'origin/master'.\nnothing to commit, working directory clean\nubuntu@ci-bentzy:/var/lib/jenkins$\n\n______________________________________________________________________________________________________\n\nSecond try: passing origin url explicitily\n\nubuntu@ci-bentzy:/var/lib/jenkins$ git remote -v                       \norigin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (fetch)\norigin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (push)\n\nubuntu@ci-bentzy:/var/lib/jenkins$ sudo vim jobs/bentzytest1/config.xml\nubuntu@ci-bentzy:/var/lib/jenkins$ sudo git add .\nubuntu@ci-bentzy:/var/lib/jenkins$ sudo git commit -m'Second try' -a\n[master 331ac84] Second try\n 1 file changed, 1 insertion(+), 1 deletion(-)\n \nubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push https://bitbucket.org/OWNER/jenkinsconf-repo.git\nUsername for 'https://bitbucket.org': USER\nPassword for 'https://USER @ bitbucket.org':\nCounting objects: 5, done.\nDelta compression using up to 2 threads.\nCompressing objects: 100% (4/4), done.\nWriting objects: 100% (5/5), 403 bytes | 0 bytes/s, done.\nTotal 5 (delta 3), reused 0 (delta 0)\nTo https://bitbucket.org/OWNER/jenkinsconf-repo.git\n   7383066..331ac84  master -> master\n  \nubuntu@ci-bentzy:/var/lib/jenkins$ git status\nOn branch master\nYour branch is ahead of 'origin/master' by 1 commit.\n  (use \"git push\" to publish your local commits)\nnothing to commit, working directory clean\n\n______________________________________________________________________________________________________\n      \nAn additional \" sudo git push\" (without explicit origin) solves the issue\n\n\n\nBentzy Sagiv\n \n\n   \n    \n \n    "},{"id":"356563","messageId":"CAGyf7-H+YoeO5bOvTkLtViMWv85cpQsxL=gxmA592WJ8=rd8hA@mail.gmail.com","threadId":"49221","inReplyTo":"MWHPR10MB1517982C582BEFB7D9171EFD9B340@MWHPR10MB1517.namprd10.prod.outlook.com","subject":"Re: Get \"Your branch is ahead of 'origin/master'\" message when explicitly passing origin url at push command","fromName":"Bryan Turner","fromEmail":"bturner@atlassian.com","sentAt":"2018-08-26T18:22:24Z","receivedAt":"2018-08-26T18:22:38Z","isPatch":false,"sender":{"key":"bturner@atlassian.com","avatar":"https://gravatar.com/avatar/16bcf3167981c1ef7c804e502642366d888a35b0d0b0a4ca01fdc442aa1acb1e?d=mp&s=160"},"body":"On Sun, Aug 26, 2018 at 4:39 AM Bentzy Sagiv <bentzy.sagiv@firemon.com> wrote:\n>\n> git version 2.7.4\n> ______________________________________________________________________________________________________\n>\n> First try: NOT passing origin url explicitly\n>\n> ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push\n\nSince you didn't specify a remote here, Git assumes origin. It uses\nyour configured \"push.default\" behavior (\"simple\" by default) to\ndetermine which refs to push and pushes your master branch to the\norigin's master branch. Since it _knows_ it pushed to origin, it\nupdates your local \"refs/remotes/origin/master\" ref with the same\ncommit it just pushed, resulting in an \"up-to-date\" message.\n\n>\n> ubuntu@ci-bentzy:/var/lib/jenkins$ git status\n> On branch master\n> Your branch is up-to-date with 'origin/master'.\n> nothing to commit, working directory clean\n> ubuntu@ci-bentzy:/var/lib/jenkins$\n>\n> ______________________________________________________________________________________________________\n>\n> Second try: passing origin url explicitily\n>\n> ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push https://bitbucket.org/OWNER/jenkinsconf-repo.git\n\nThis, on the other hand, _is not pushing to a configured remote_. It's\npushing to an explicit URL, which happens to match the URL of a\nconfigured remote. But it's still not a configured remote. It's using\norigin's URL, but you didn't push to origin. As a result,\n\"refs/remotes/origin/master\" is not updated, and you get an \"ahead\"\nmessage.\n\n>\n> ubuntu@ci-bentzy:/var/lib/jenkins$ git status\n> On branch master\n> Your branch is ahead of 'origin/master' by 1 commit.\n>   (use \"git push\" to publish your local commits)\n> nothing to commit, working directory clean\n>\n> ______________________________________________________________________________________________________\n>\n> An additional \" sudo git push\" (without explicit origin) solves the issue\n\nEverything here is working as intended. If you want to push to a\n_remote_, you either need to:\n- Name the remote (\"git push origin\"), or\n- Leave it off, so Git will assume origin (\"git push\")\n\nPushing to a URL that matches a remote's URL is _not_ pushing to a\nremote. It's pushing to an explicit URL.\n\nHope this helps,\nBryan Turner\n>\n>\n>\n"},{"id":"356583","messageId":"MWHPR10MB1517F19A71CFC59A66530DFE9B0B0@MWHPR10MB1517.namprd10.prod.outlook.com","threadId":"49221","inReplyTo":"CAGyf7-H+YoeO5bOvTkLtViMWv85cpQsxL=gxmA592WJ8=rd8hA@mail.gmail.com","subject":"Re: Get \"Your branch is ahead of 'origin/master'\" message when explicitly passing origin url at push command","fromName":"Bentzy Sagiv","fromEmail":"bentzy.sagiv@firemon.com","sentAt":"2018-08-27T15:19:39Z","receivedAt":"2018-08-27T15:19:46Z","isPatch":false,"sender":{"key":"bentzy.sagiv@firemon.com","avatar":null},"body":"Thanks, it really helped to understand.\nSince what I want to do is to run git pull/push from within a script in a Jenkins job and Jenkins already has the git user&password stored, I thougth is odd to store them at a git credential helper.\nMy solution is running (before git pull/push):\n    git config remote.origin.url https://$GIT_USER:$GIT_PASSWORD@bitbucket.org/...\nwhile at the start of the script trapping EXIT signal and resetting origin as following:\n    trap \"sudo git config remote.origin.url https://$GIT_USER@bitbucket.org/...\" EXIT\nMake sense or am I missing something?\n\nThanks in advance,\nBentzy Sagiv\n   \n    \n \n    \n\n\n\nFrom: Bryan Turner <bturner@atlassian.com>\nSent: Sunday, August 26, 2018 9:22 PM\nTo: Bentzy Sagiv\nCc: Git Users\nSubject: Re: Get \"Your branch is ahead of 'origin/master'\" message when explicitly passing origin url at push command\n  \n\nOn Sun, Aug 26, 2018 at 4:39 AM Bentzy Sagiv <bentzy.sagiv@firemon.com> wrote:\n>\n> git version 2.7.4\n> ______________________________________________________________________________________________________\n>\n> First try: NOT passing origin url explicitly\n>\n> ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push\n\nSince you didn't specify a remote here, Git assumes origin. It uses\nyour configured \"push.default\" behavior (\"simple\" by default) to\ndetermine which refs to push and pushes your master branch to the\norigin's master branch. Since it _knows_ it pushed to origin, it\nupdates your local \"refs/remotes/origin/master\" ref with the same\ncommit it just pushed, resulting in an \"up-to-date\" message.\n\n>\n> ubuntu@ci-bentzy:/var/lib/jenkins$ git status\n> On branch master\n> Your branch is up-to-date with 'origin/master'.\n> nothing to commit, working directory clean\n> ubuntu@ci-bentzy:/var/lib/jenkins$\n>\n> ______________________________________________________________________________________________________\n>\n> Second try: passing origin url explicitily\n>\n> ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push  https://bitbucket.org/OWNER/jenkinsconf-repo.git\n\nThis, on the other hand, _is not pushing to a configured remote_. It's\npushing to an explicit URL, which happens to match the URL of a\nconfigured remote. But it's still not a configured remote. It's using\norigin's URL, but you didn't push to origin. As a result,\n\"refs/remotes/origin/master\" is not updated, and you get an \"ahead\"\nmessage.\n\n>\n> ubuntu@ci-bentzy:/var/lib/jenkins$ git status\n> On branch master\n> Your branch is ahead of 'origin/master' by 1 commit.\n>   (use \"git push\" to publish your local commits)\n> nothing to commit, working directory clean\n>\n> ______________________________________________________________________________________________________\n>\n> An additional \" sudo git push\" (without explicit origin) solves the issue\n\nEverything here is working as intended. If you want to push to a\n_remote_, you either need to:\n- Name the remote (\"git push origin\"), or\n- Leave it off, so Git will assume origin (\"git push\")\n\nPushing to a URL that matches a remote's URL is _not_ pushing to a\nremote. It's pushing to an explicit URL.\n\nHope this helps,\nBryan Turner\n>\n>\n>\n    "}]}