git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Get "Your branch is ahead of 'origin/master'" message when explicitly passing origin url at push command
@ 2018-08-26 11:37 Bentzy Sagiv
  2018-08-26 18:22 ` Bryan Turner
  0 siblings, 1 reply; 3+ messages in thread
From: Bentzy Sagiv @ 2018-08-26 11:37 UTC (permalink / raw)
  To: git@vger.kernel.org

git version 2.7.4
______________________________________________________________________________________________________

First try: NOT passing origin url explicitly

ubuntu@ci-bentzy:/var/lib/jenkins$ git remote -v
origin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (fetch)
origin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (push)

ubuntu@ci-bentzy:/var/lib/jenkins$ sudo vim jobs/bentzytest1/config.xml
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git add .
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git commit -m'First try' -a
[master b8549c3] First try
 1 file changed, 2 insertions(+), 2 deletions(-)
 
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push
Password for 'https://USER @ bitbucket.org':
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 399 bytes | 0 bytes/s, done.
Total 5 (delta 3), reused 0 (delta 0)
To https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git
   d2cc229..b8549c3  master -> master
  
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$ git remote -v                       
origin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (fetch)
origin  https://USER @ bitbucket.org/OWNER/jenkinsconf-repo.git (push)

ubuntu@ci-bentzy:/var/lib/jenkins$ sudo vim jobs/bentzytest1/config.xml
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git add .
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git commit -m'Second try' -a
[master 331ac84] Second try
 1 file changed, 1 insertion(+), 1 deletion(-)
 
ubuntu@ci-bentzy:/var/lib/jenkins$ sudo git push https://bitbucket.org/OWNER/jenkinsconf-repo.git
Username for 'https://bitbucket.org': USER
Password for 'https://USER @ bitbucket.org':
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 403 bytes | 0 bytes/s, done.
Total 5 (delta 3), reused 0 (delta 0)
To https://bitbucket.org/OWNER/jenkinsconf-repo.git
   7383066..331ac84  master -> master
  
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



Bentzy Sagiv
 

   
    
 
    

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Get "Your branch is ahead of 'origin/master'" message when explicitly passing origin url at push command
  2018-08-26 11:37 Get "Your branch is ahead of 'origin/master'" message when explicitly passing origin url at push command Bentzy Sagiv
@ 2018-08-26 18:22 ` Bryan Turner
  2018-08-27 15:19   ` Bentzy Sagiv
  0 siblings, 1 reply; 3+ messages in thread
From: Bryan Turner @ 2018-08-26 18:22 UTC (permalink / raw)
  To: bentzy.sagiv; +Cc: Git Users

On Sun, Aug 26, 2018 at 4:39 AM Bentzy Sagiv <bentzy.sagiv@firemon.com> wrote:
>
> 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.

>
> 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.

>
> 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
>
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Get "Your branch is ahead of 'origin/master'" message when explicitly passing origin url at push command
  2018-08-26 18:22 ` Bryan Turner
@ 2018-08-27 15:19   ` Bentzy Sagiv
  0 siblings, 0 replies; 3+ messages in thread
From: Bentzy Sagiv @ 2018-08-27 15:19 UTC (permalink / raw)
  To: Bryan Turner; +Cc: Git Users

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:
>
> 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.

>
> 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.

>
> 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
>
>
>
    

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-27 15:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-26 11:37 Get "Your branch is ahead of 'origin/master'" message when explicitly passing origin url at push command Bentzy Sagiv
2018-08-26 18:22 ` Bryan Turner
2018-08-27 15:19   ` Bentzy Sagiv

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).