threads / discuss / 31053

pushing branches

Subject: pushing branches

## tl;dr

13 messages between Jul 20, 2012 and Jul 22, 2012.

replies: 12people: 5as markdown or json

Thiago Farina· Jul 20, 2012, 15:26 UTC · lore
Hi,
How can I push a working branch to github inside it?
E.g:

# On master: $ git checkout -b feature-work

# On feature-work # vi, hack, commit, ready to push $ git push origin master # here I expected it would working pushing my commits to a feature-work branch in github. Or if I omit master it gives me a [rejected] error. Everything up-to-date.

$ git checkout master $ git push origin feature-work # Now the branch is pushed.

Thanks,
Junio C Hamano· Jul 20, 2012, 15:46 UTC · re: Thiago Farina · lore

Re: pushing branches

Thiago Farina <tfransosi@gmail.com> writes:
Show 10 quoted lines
> How can I push a working branch to github inside it?
>
> E.g:
>
> # On master:
> $ git checkout -b feature-work
>
> # On feature-work
> # vi, hack, commit, ready to push
> $ git push origin master # here I expected it would working pushing my

"git push origin master" is a short-hand for "git push origin refs/heads/master:refs/heads/master" to update their master branch with what you have in your master branch.

See output from
    $ git push --help
for details.

I think you are trying to update, while on your feature-work branch, their master with your feature-work branch (or more generally, the current HEAD), so

    $ git push origin HEAD:master
is perhaps what you are looking for?    
Thiago Farina· Jul 20, 2012, 15:49 UTC · re: Junio C Hamano · lore

Re: pushing branches

On Fri, Jul 20, 2012 at 12:46 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 30 quoted lines
> Thiago Farina <tfransosi@gmail.com> writes:
>
>> How can I push a working branch to github inside it?
>>
>> E.g:
>>
>> # On master:
>> $ git checkout -b feature-work
>>
>> # On feature-work
>> # vi, hack, commit, ready to push
>> $ git push origin master # here I expected it would working pushing my
>
> "git push origin master" is a short-hand for "git push origin
> refs/heads/master:refs/heads/master" to update their master branch
> with what you have in your master branch.
>
> See output from
>
>     $ git push --help
>
> for details.
>
> I think you are trying to update, while on your feature-work branch,
> their master with your feature-work branch (or more generally, the
> current HEAD), so
>
>     $ git push origin HEAD:master
>
> is perhaps what you are looking for?

What I'm looking for is to upload/create the remote branch in github from inside my local branch, without having to checkout master in order to do so.

PJ Weisberg· Jul 20, 2012, 19:19 UTC · re: Thiago Farina · lore

Re: pushing branches

On Fri, Jul 20, 2012 at 8:49 AM, Thiago Farina <tfransosi@gmail.com> wrote:
> What I'm looking for is to upload/create the remote branch in github
> from inside my local branch, without having to checkout master in
> order to do so.
In that case, do exactly what you did, except don't checkout master.
-PJ

Gehm's Corollary to Clark's Law: Any technology distinguishable from magic is insufficiently advanced.

Thiago Farina· Jul 21, 2012, 01:40 UTC · re: PJ Weisberg · lore

Re: pushing branches

On Fri, Jul 20, 2012 at 4:19 PM, PJ Weisberg <pj@irregularexpressions.net> wrote:

Show 8 quoted lines
> On Fri, Jul 20, 2012 at 8:49 AM, Thiago Farina <tfransosi@gmail.com> wrote:
>
>> What I'm looking for is to upload/create the remote branch in github
>> from inside my local branch, without having to checkout master in
>> order to do so.
>
> In that case, do exactly what you did, except don't checkout master.
>

Why you suggest that? If I demonstrated that origin master or just origin in the current branch doesn't do what I want, i.e, push it to github.

PJ Weisberg· Jul 21, 2012, 01:58 UTC · re: Thiago Farina · lore

Re: pushing branches

On Fri, Jul 20, 2012 at 6:40 PM, Thiago Farina <tfransosi@gmail.com> wrote:
Show 13 quoted lines
> On Fri, Jul 20, 2012 at 4:19 PM, PJ Weisberg
> <pj@irregularexpressions.net> wrote:
>> On Fri, Jul 20, 2012 at 8:49 AM, Thiago Farina <tfransosi@gmail.com> wrote:
>>
>>> What I'm looking for is to upload/create the remote branch in github
>>> from inside my local branch, without having to checkout master in
>>> order to do so.
>>
>> In that case, do exactly what you did, except don't checkout master.
>>
> Why you suggest that? If I demonstrated that origin master or just
> origin in the current branch doesn't do what I want, i.e, push it to
> github.

In your original email, you had one command that did what you wanted and one that didn't.

$ git push origin master $ git push origin feature-work

Can you spot the difference between them?

Like Konstantin said, you can look into the different options for push.default, but don't expect Git to push one branch when you told it to push another.

-PJ

Gehm's Corollary to Clark's Law: Any technology distinguishable from magic is insufficiently advanced.

Thiago Farina· Jul 21, 2012, 02:10 UTC · re: PJ Weisberg · lore

Re: pushing branches

On Fri, Jul 20, 2012 at 10:58 PM, PJ Weisberg <pj@irregularexpressions.net> wrote:

Show 8 quoted lines
> In your original email, you had one command that did what you wanted
> and one that didn't.
>
> $ git push origin master
> $ git push origin feature-work
>
> Can you spot the difference between them?
>
Do'h, now I can see the idiocy that I was doing.

If I'm understanding this better, $ git push origin master tells git to push to remote origin, the contents of my master branch.

And then,

$ git push origin feature-work tells git to push to remote origin to push the contents of feature-work branch.

Hence does not make sense to ask git to do "push origin master" while inside feature-work branch.

Show 8 quoted lines
> Like Konstantin said, you can look into the different options for
> push.default, but don't expect Git to push one branch when you told it
> to push another.
>
> -PJ
>
> Gehm's Corollary to Clark's Law: Any technology distinguishable from
> magic is insufficiently advanced.
Junio C Hamano· Jul 21, 2012, 19:33 UTC · re: Thiago Farina · lore

Re: pushing branches

Thiago Farina <tfransosi@gmail.com> writes:
Show 5 quoted lines
> Do'h, now I can see the idiocy that I was doing.
>
> If I'm understanding this better,
> $ git push origin master
> tells git to push to remote origin, the contents of my master branch.

Yes, add "to the 'master' at the 'origin'" at the end of the sentence and you are perfect.

> And then,
>
> $ git push origin feature-work
> tells git to push to remote origin to push the contents of feature-work branch.
Yes.
> Hence does not make sense to ask git to do "push origin master" while
> inside feature-work branch.

No. As long as you know your master is ready and suitable to be published when you ask "push", the command perfectly makes sense; it does not matter on what branch you are on.

You may say
	$ git checkout master
        ... work work work ...
        $ make test
        ... ahh, perfection! ...
        $ git checkout -b feature
        ... let's build a bit more ..
        ... while I am having fun, let's not forget to push the
        ... part that is already solid out
        $ git push origin master

and that is perfectly fine without "git checkout master" before pushing (and "git checkout feature" after to come back to what you were doing).

Thiago Farina· Jul 22, 2012, 02:54 UTC · re: Junio C Hamano · lore

Re: pushing branches

On Sat, Jul 21, 2012 at 4:33 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 24 quoted lines
> Yes.
>
>> Hence does not make sense to ask git to do "push origin master" while
>> inside feature-work branch.
>
> No.  As long as you know your master is ready and suitable to be
> published when you ask "push", the command perfectly makes sense; it
> does not matter on what branch you are on.
>
> You may say
>
>         $ git checkout master
>         ... work work work ...
>         $ make test
>         ... ahh, perfection! ...
>         $ git checkout -b feature
>         ... let's build a bit more ..
>         ... while I am having fun, let's not forget to push the
>         ... part that is already solid out
>         $ git push origin master
>
> and that is perfectly fine without "git checkout master" before
> pushing (and "git checkout feature" after to come back to what you
> were doing).

In my case it wouldn't because I do not modify my master branch, I just fetch upstream, merge upstream/master into my local master branch and switch to feature-work, then git push origin master will always give me "Everything up-to-date" I suppose (that is what always happen in my case/workflow).

And just learned, the answer to my question is, while in feature-work branch, 'git push origin feature-work'. Which does what I wanted.

Junio C Hamano· Jul 22, 2012, 18:40 UTC · re: Thiago Farina · lore

Re: pushing branches

Thiago Farina <tfransosi@gmail.com> writes:
Show 15 quoted lines
> On Sat, Jul 21, 2012 at 4:33 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Yes.
>>
>>> Hence does not make sense to ask git to do "push origin master" while
>>> inside feature-work branch.
>> ...
>> No.  As long as you know your master is ready and suitable to be
>> published when you ask "push", the command perfectly makes sense; it
>> does not matter on what branch you are on.
>> ...
> In my case it wouldn't because I do not modify my master branch, I
> just fetch upstream, merge upstream/master into my local master branch
> and switch to feature-work, then git push origin master will always
> give me "Everything up-to-date" I suppose (that is what always happen
> in my case/workflow).

It would not make _any_ sense to ask "git push origin master" regardless of which branch you are on if that is the case, as you are not modifying, then.

PJ Weisberg· Jul 20, 2012, 15:46 UTC · re: Thiago Farina · lore

Re: pushing branches

On Fri, Jul 20, 2012 at 8:26 AM, Thiago Farina <tfransosi@gmail.com> wrote:
Show 18 quoted lines
> Hi,
>
> How can I push a working branch to github inside it?
>
> E.g:
>
> # On master:
> $ git checkout -b feature-work
>
> # On feature-work
> # vi, hack, commit, ready to push
> $ git push origin master # here I expected it would working pushing my
> commits to a feature-work branch in github. Or if I omit master it
> gives me a [rejected] error.
> Everything up-to-date.
>
> $ git checkout master
> $ git push origin feature-work # Now the branch is pushed.
???

I must be missing something. It looks like the reason it didn't push feature-work the first time is because you told it to push master instead.

-PJ

Gehm's Corollary to Clark's Law: Any technology distinguishable from magic is insufficiently advanced.

Konstantin Khomoutov· Jul 20, 2012, 15:49 UTC · re: Thiago Farina · lore

Re: pushing branches

On Fri, 20 Jul 2012 12:26:09 -0300 Thiago Farina <tfransosi@gmail.com> wrote:

Show 12 quoted lines
> How can I push a working branch to github inside it?
> 
> E.g:
> 
> # On master:
> $ git checkout -b feature-work
> 
> # On feature-work
> # vi, hack, commit, ready to push
> $ git push origin master # here I expected it would working pushing my
> commits to a feature-work branch in github. Or if I omit master it
> gives me a [rejected] error.

$ git push origin master means "update the branch 'master' in the remote repository with the contents of the branch 'master' in the local repository". Read the "git push" manual.

> $ git checkout master
> $ git push origin feature-work # Now the branch is pushed.

Sure, but it has nothing to do with the previous checkout command: you just told Git to push the contents of your local branch "feature-work" to a remote branch "feature-work" which presumably does not exist and gets created as a result of your push.

If you want to update the remote "master" branch with the contents of your local "feature-work" branch, do $ git push origin feature-work:master

As stated below, you should really read the git push manual and reading through the appropriate sections of the http://git-scm.com/book is also highly advised.

Also consider reading about the "push.default" configuration variable in the git config manual--this might save you from scratching your head when you try to do simple `git push origin` without specifying any branches: here again your expectation might differ from the Git defaults.

Matthieu Moy· Jul 20, 2012, 15:53 UTC · re: Thiago Farina · lore

Re: pushing branches

Thiago Farina <tfransosi@gmail.com> writes:
> $ git push origin master # here I expected it would working pushing my
> commits to a feature-work branch in github. Or if I omit master it
> gives me a [rejected] error.
> Everything up-to-date.

If your workflow is to push one branch at a time, and you have the same naming locally and remotely (i.e. your local branch feature-work should be pushed as feature-work on github), then you probably want to set the variable 'push.default' to either 'current', 'upstream' or 'simple' if you use the last version of Git. Read about it there:

  http://git-scm.com/docs/git-config
(search push.default)
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads