Thread overview
[dmd-internals] Git question: How do I push a *single* branch?
Nov 21, 2011
Don Clugston
Nov 21, 2011
Jonathan M Davis
Nov 21, 2011
Don Clugston
Nov 21, 2011
Martin Nowak
Nov 21, 2011
Don Clugston
Nov 21, 2011
Martin Nowak
Dec 01, 2011
Leandro Lucarella
Nov 21, 2011
Jason House
Nov 21, 2011
Christian Kamm
November 21, 2011
In my local repository I have two branches, branch1 and branch2.
I publish branch1 to github:
git push origin : branch1
A side-effect of this, is that it automatically makes branch1 a remote
tracking branch.

Now, I add an extra commit to branch1, but I don't want to push it yet.
But I do want to push branch2.
So I type:  git push origin : branch2
This creates branch2, BUT it also pushes branch1 as well!
How do I stop this?

 I can't see anything in the manual for git push that explains this.
How can I push branch2 *only* ?
November 21, 2011
On Monday, November 21, 2011 10:01:30 Don Clugston wrote:
> In my local repository I have two branches, branch1 and branch2.
> I publish branch1 to github:
> git push origin : branch1
> A side-effect of this, is that it automatically makes branch1 a remote
> tracking branch.
> 
> Now, I add an extra commit to branch1, but I don't want to push it yet.
> But I do want to push branch2.
> So I type:  git push origin : branch2
> This creates branch2, BUT it also pushes branch1 as well!
> How do I stop this?
> 
>  I can't see anything in the manual for git push that explains this.
> How can I push branch2 *only* ?

I would do

git-push origin branch1

That only pushes branch1 regardless of what's going on in other branches. It creates the branch in origin if it doesn't exist there and updates it otherwise. You then _remove_ a branch in origin by doing

git-push origin :branch1

So, I'm surprised that

git-push origin : branch1

isn't deleting branch1 in origin. I guess that the space makes all the difference. I'd have to go digging throught Pro Git and the like to know what

git-push origin : branch1

is really doing.

- Jonathan M Davis
November 21, 2011
On 21 November 2011 10:12, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> On Monday, November 21, 2011 10:01:30 Don Clugston wrote:
>> In my local repository I have two branches, branch1 and branch2.
>> I publish branch1 to github:
>> git push origin : branch1
>> A side-effect of this, is that it automatically makes branch1 a remote
>> tracking branch.
>>
>> Now, I add an extra commit to branch1, but I don't want to push it yet.
>> But I do want to push branch2.
>> So I type: ?git push origin : branch2
>> This creates branch2, BUT it also pushes branch1 as well!
>> How do I stop this?
>>
>> ?I can't see anything in the manual for git push that explains this. How can I push branch2 *only* ?
>
> I would do
>
> git-push origin branch1
>
> That only pushes branch1 regardless of what's going on in other branches. It creates the branch in origin if it doesn't exist there and updates it otherwise. You then _remove_ a branch in origin by doing
>
> git-push origin :branch1
>
> So, I'm surprised that
>
> git-push origin : branch1
>
> isn't deleting branch1 in origin. I guess that the space makes all the difference. I'd have to go digging throught Pro Git and the like to know what
>
> git-push origin : branch1
>
> is really doing.

Thanks, you're right!

Turns out that " : " (with spaces) means "push everything".

So:
git push origin : branch1  ---> push everything. The "branch1"
argument is irrelevant, except that it must exist locally
git push origin:branch1    --> (this is an error)
git push origin origin:branch1 --> push currently active branch to
remote branch1, which must already exist.
git push origin :branch1   ---> delete remote branch1
git remote rm branch1     ---> delete config section remote.branch1
git branch rm branch1     ---> copy branch1 to new branch called 'rm'
Use --force to make a git command do something that may cause loss of
information, except for git branch, where you convert the option to
uppercase instead.
November 21, 2011
On Mon, 21 Nov 2011 11:31:50 +0100, Don Clugston <dclugston at googlemail.com> wrote:

> On 21 November 2011 10:12, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
>> On Monday, November 21, 2011 10:01:30 Don Clugston wrote:
>>> In my local repository I have two branches, branch1 and branch2.
>>> I publish branch1 to github:
>>> git push origin : branch1
>>> A side-effect of this, is that it automatically makes branch1 a remote
>>> tracking branch.
>>>
>>> Now, I add an extra commit to branch1, but I don't want to push it yet.
>>> But I do want to push branch2.
>>> So I type:  git push origin : branch2
>>> This creates branch2, BUT it also pushes branch1 as well!
>>> How do I stop this?
>>>
>>>  I can't see anything in the manual for git push that explains this.
>>> How can I push branch2 *only* ?
>>
>> I would do
>>
>> git-push origin branch1
>>
>> That only pushes branch1 regardless of what's going on in other
>> branches. It
>> creates the branch in origin if it doesn't exist there and updates it
>> otherwise. You then _remove_ a branch in origin by doing
>>
>> git-push origin :branch1
>>
>> So, I'm surprised that
>>
>> git-push origin : branch1
>>
>> isn't deleting branch1 in origin. I guess that the space makes all the difference. I'd have to go digging throught Pro Git and the like to know what
>>
>> git-push origin : branch1
>>
>> is really doing.
>
> Thanks, you're right!
>
> Turns out that " : " (with spaces) means "push everything".
>
They would have done better to only allow '+:' to push matching branches.

> So:
> git push origin : branch1  ---> push everything. The "branch1"
> argument is irrelevant, except that it must exist locally
It says matching, so the need to exist locally and at the remote site. I think 'git push origin :' is actually equivalent to 'git push origin'.

> git push origin:branch1    --> (this is an error)
> git push origin origin:branch1 --> push currently active branch to
> remote branch1, which must already exist.
This is a little odd but origin implicitly matches refs/remotes/origin/HEAD.

> git push origin :branch1   ---> delete remote branch1
As in pushing an empty sha-1 to a branch.

> git remote rm branch1     ---> delete config section remote.branch1
> git branch rm branch1     ---> copy branch1 to new branch called 'rm'
> Use --force to make a git command do something that may cause loss of
> information, except for git branch, where you convert the option to
> uppercase instead.
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals

Another neat feature is being able to specify relative commits or SHA-1s
as src ref like
'abcdef1:master' or 'HEAD~2:master'.
November 21, 2011
On Nov 21, 2011, at 5:31 AM, Don Clugston <dclugston at googlemail.com> wrote:
> 
> Thanks, you're right!
> 
> Turns out that " : " (with spaces) means "push everything".
> 
> So:
> git push origin : branch1  ---> push everything. The "branch1"
> argument is irrelevant, except that it must exist locally
> git push origin:branch1    --> (this is an error)
> git push origin origin:branch1 --> push currently active branch to
> remote branch1, which must already exist.
> git push origin :branch1   ---> delete remote branch1
> git remote rm branch1     ---> delete config section remote.branch1
> git branch rm branch1     ---> copy branch1 to new branch called 'rm'

... and this is why git is confusing!
November 21, 2011
On 21 November 2011 12:35, Martin Nowak <dawg at dawgfoto.de> wrote:
> On Mon, 21 Nov 2011 11:31:50 +0100, Don Clugston <dclugston at googlemail.com> wrote:
>
>> On 21 November 2011 10:12, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
>>>
>>> On Monday, November 21, 2011 10:01:30 Don Clugston wrote:
>>>>
>>>> In my local repository I have two branches, branch1 and branch2.
>>>> I publish branch1 to github:
>>>> git push origin : branch1
>>>> A side-effect of this, is that it automatically makes branch1 a remote
>>>> tracking branch.
>>>>
>>>> Now, I add an extra commit to branch1, but I don't want to push it yet.
>>>> But I do want to push branch2.
>>>> So I type: ?git push origin : branch2
>>>> This creates branch2, BUT it also pushes branch1 as well!
>>>> How do I stop this?
>>>>
>>>> ?I can't see anything in the manual for git push that explains this. How can I push branch2 *only* ?
>>>
>>> I would do
>>>
>>> git-push origin branch1
>>>
>>> That only pushes branch1 regardless of what's going on in other branches.
>>> It
>>> creates the branch in origin if it doesn't exist there and updates it
>>> otherwise. You then _remove_ a branch in origin by doing
>>>
>>> git-push origin :branch1
>>>
>>> So, I'm surprised that
>>>
>>> git-push origin : branch1
>>>
>>> isn't deleting branch1 in origin. I guess that the space makes all the difference. I'd have to go digging throught Pro Git and the like to know what
>>>
>>> git-push origin : branch1
>>>
>>> is really doing.
>>
>> Thanks, you're right!
>>
>> Turns out that " : " (with spaces) means "push everything".
>>
> They would have done better to only allow '+:' to push matching branches.
>
>> So:
>> git push origin : branch1 ?---> push everything. The "branch1"
>> argument is irrelevant, except that it must exist locally
>
> It says matching, so the need to exist locally and at the remote site. I think 'git push origin :' is actually equivalent to 'git push origin'.

Yes. But once there's a ' : ' in the list, it makes no sense for other branches to be listed. It should be an error.

>> git push origin:branch1 ? ?--> (this is an error)
>> git push origin origin:branch1 --> push currently active branch to
>> remote branch1, which must already exist.
>
> This is a little odd but origin implicitly matches refs/remotes/origin/HEAD.
>
>> git push origin :branch1 ? ---> delete remote branch1
>
> As in pushing an empty sha-1 to a branch.

I've heard that explanation before, but are there any other situations in git where an empty string is valid as a sha-1?
November 21, 2011
On Mon, 21 Nov 2011 15:35:55 +0100, Don Clugston <dclugston at googlemail.com> wrote:

> On 21 November 2011 12:35, Martin Nowak <dawg at dawgfoto.de> wrote:
>> On Mon, 21 Nov 2011 11:31:50 +0100, Don Clugston
>> <dclugston at googlemail.com>
>> wrote:
>>
>>> On 21 November 2011 10:12, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
>>>>
>>>> On Monday, November 21, 2011 10:01:30 Don Clugston wrote:
>>>>>
>>>>> In my local repository I have two branches, branch1 and branch2.
>>>>> I publish branch1 to github:
>>>>> git push origin : branch1
>>>>> A side-effect of this, is that it automatically makes branch1 a
>>>>> remote
>>>>> tracking branch.
>>>>>
>>>>> Now, I add an extra commit to branch1, but I don't want to push it
>>>>> yet.
>>>>> But I do want to push branch2.
>>>>> So I type:  git push origin : branch2
>>>>> This creates branch2, BUT it also pushes branch1 as well!
>>>>> How do I stop this?
>>>>>
>>>>>  I can't see anything in the manual for git push that explains this.
>>>>> How can I push branch2 *only* ?
>>>>
>>>> I would do
>>>>
>>>> git-push origin branch1
>>>>
>>>> That only pushes branch1 regardless of what's going on in other
>>>> branches.
>>>> It
>>>> creates the branch in origin if it doesn't exist there and updates it
>>>> otherwise. You then _remove_ a branch in origin by doing
>>>>
>>>> git-push origin :branch1
>>>>
>>>> So, I'm surprised that
>>>>
>>>> git-push origin : branch1
>>>>
>>>> isn't deleting branch1 in origin. I guess that the space makes all the
>>>> difference. I'd have to go digging throught Pro Git and the like to
>>>> know
>>>> what
>>>>
>>>> git-push origin : branch1
>>>>
>>>> is really doing.
>>>
>>> Thanks, you're right!
>>>
>>> Turns out that " : " (with spaces) means "push everything".
>>>
>> They would have done better to only allow '+:' to push matching branches.
>>
>>> So:
>>> git push origin : branch1  ---> push everything. The "branch1"
>>> argument is irrelevant, except that it must exist locally
>>
>> It says matching, so the need to exist locally and at the remote site. I think 'git push origin :' is actually equivalent to 'git push origin'.
>
> Yes. But once there's a ' : ' in the list, it makes no sense for other branches to be listed. It should be an error.
>
>>> git push origin:branch1    --> (this is an error)
>>> git push origin origin:branch1 --> push currently active branch to
>>> remote branch1, which must already exist.
>>
>> This is a little odd but origin implicitly matches refs/remotes/origin/HEAD.
>>
>>> git push origin :branch1   ---> delete remote branch1
>>
>> As in pushing an empty sha-1 to a branch.
>
> I've heard that explanation before, but are there any other situations in git where an empty string is valid as a sha-1?

Probably not. I didn't wanted to claim that these commands are somewhat
consistent.
But at least once being learned and justified by arbitrary explanations
you don't have
to type a lot.

> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals
November 21, 2011
On Monday 21 November 2011 10:01 Don Clugston wrote:
>  I can't see anything in the manual for git push that explains this.
> How can I push branch2 *only* ?

I recommend setting push.default to tracking, then you can just use 'git push' while on branch2 to push it to its upstream branch.

We have a wiki page about git setup that also has other recommendations like enabling rerere and setting core.autocrlf: http://wiki.qt-project.org/Setting_up_Gerrit#Configuring_Git .

Cheers,
Christian
December 01, 2011
Don Clugston, el 21 de noviembre a las 15:35 me escribiste:
> >> git push origin : branch1 ?---> push everything. The "branch1" argument is irrelevant, except that it must exist locally
> >
> > It says matching, so the need to exist locally and at the remote site. I think 'git push origin :' is actually equivalent to 'git push origin'.
> 
> Yes. But once there's a ' : ' in the list, it makes no sense for other branches to be listed. It should be an error.

Report it! Git devs are really concerned about this usability issues and
always improving git in that way. Just send an e-mail to
git at vger.kernel.org mailing list. They even do an usability survey every
year, results from the last one can be seen here:
https://www.survs.com/results/Q5CA9SKQ/P7DE07F0PL

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/