git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Get "Your branch is ahead of 'origin/master'" message when explicitly passing origin url at push command

From
BSBentzy Sagiv <bentzy.sagiv@firemon.com>
Date
Aug 27, 2018, 15:19 UTC
Message-ID
<MWHPR10MB1517F19A71CFC59A66530DFE9B0B0@MWHPR10MB1517.namprd10.prod.outlook.com>
In-Reply-To
<CAGyf7-H+YoeO5bOvTkLtViMWv85cpQsxL=gxmA592WJ8=rd8hA@mail.gmail.com>
Thanks, it really helped to understand.
Since 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.
My solution is running (before git pull/push):
    git config remote.origin.url https://$GIT_USER:$GIT_PASSWORD@bitbucket.org/...
while at the start of the script trapping EXIT signal and resetting origin as following:
    trap "sudo git config remote.origin.url https://$GIT_USER@bitbucket.org/..." EXIT
Make sense or am I missing something?
Thanks in advance,
Bentzy Sagiv
   
    
 
    
From: Bryan Turner <bturner@atlassian.com>
Sent: Sunday, August 26, 2018 9:22 PM
To: Bentzy Sagiv
Cc: Git Users
Subject: Re: Get "Your branch is ahead of 'origin/master'" message when explicitly passing origin url at push command
  
On Sun, Aug 26, 2018 at 4:39 AM Bentzy Sagiv <bentzy.sagiv@firemon.com> wrote:
Show 7 quoted lines
>
> git version 2.7.4
> ______________________________________________________________________________________________________
>
> First try: NOT passing origin url explicitly
>
> ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push

Since you didn't specify a remote here, Git assumes origin. It uses your configured "push.default" behavior ("simple" by default) to determine which refs to push and pushes your master branch to the origin's master branch. Since it _knows_ it pushed to origin, it updates your local "refs/remotes/origin/master" ref with the same commit it just pushed, resulting in an "up-to-date" message.

Show 12 quoted lines
>
> ubuntu@ci-bentzy:/var/lib/jenkins$ git status
> On branch master
> Your branch is up-to-date with 'origin/master'.
> nothing to commit, working directory clean
> ubuntu@ci-bentzy:/var/lib/jenkins$
>
> ______________________________________________________________________________________________________
>
> Second try: passing origin url explicitily
>
> ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push  https://bitbucket.org/OWNER/jenkinsconf-repo.git

This, on the other hand, _is not pushing to a configured remote_. It's pushing to an explicit URL, which happens to match the URL of a configured remote. But it's still not a configured remote. It's using origin's URL, but you didn't push to origin. As a result, "refs/remotes/origin/master" is not updated, and you get an "ahead" message.

Show 10 quoted lines
>
> ubuntu@ci-bentzy:/var/lib/jenkins$ git status
> On branch master
> Your branch is ahead of 'origin/master' by 1 commit.
>   (use "git push" to publish your local commits)
> nothing to commit, working directory clean
>
> ______________________________________________________________________________________________________
>
> An additional " sudo git push" (without explicit origin) solves the issue
Everything here is working as intended. If you want to push to a
_remote_, you either need to:
- Name the remote ("git push origin"), or
- Leave it off, so Git will assume origin ("git push")

Pushing to a URL that matches a remote's URL is _not_ pushing to a remote. It's pushing to an explicit URL.

Hope this helps, Bryan Turner

>
>
>
Previous: Bryan Turner
Message 3 of 3 in “Get "Your branch is ahead of 'origin/master'" message when explicitly passing origin url at push command”
  1. Bentzy SagivAug 26, 2018
  2. Bryan TurnerAug 26, 2018
  3. Bentzy SagivAug 27, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.