threads / bug / 29353

clone bug

Subject: clone bug

## tl;dr

3 messages between Jan 12, 2012 and Jan 12, 2012.

replies: 2people: 3as markdown or json

Alexey Kuznetsov· Jan 12, 2012, 13:43 UTC · lore
Hello!

Seems like I found a bug in the clone / push logic. I'm trying to clone remote branch master into local branch called common and unable to push back common to master. Git trying to push local master from different origin to common/master instead.

Here is a simple example:
# mkdir 123
# git init
# > 123
# git add .
# git commit -m "initial"
# git branch
axet-laptop:123 axet$ git branch
* master
# git remote add common https://github.com/axet/common-bin.git
# git fetch common
From https://github.com/axet/common-bin
 * [new branch]      master     -> common/master
?? already strange master (local) to the remote common/master

# axet-laptop:123 axet$ git checkout -b common common/master Branch common set up to track remote branch master from common. Switched to a new branch 'common'

# axet-laptop:123 axet$ git branch
* common
  master
axet-laptop:123 axet$

# cat .git/config [...]

[branch "common"]
	remote = common
	merge = refs/heads/master
?? correct
axet-laptop:123 axet$ git pull
Already up-to-date.
axet-laptop:123 axet$ git push
To https://github.com/axet/common-bin.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/axet/common-bin.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
axet-laptop:123 axet$
it tries to push local master to remote common/master which is not correct.
-- AK
Thomas Rast· Jan 12, 2012, 14:32 UTC · re: Alexey Kuznetsov · lore

Re: clone bug

Alexey Kuznetsov <kuznetsov.alexey@gmail.com> writes:
Show 20 quoted lines
>
> [branch "common"]
> 	remote = common
> 	merge = refs/heads/master
>
> ?? correct
>
> axet-laptop:123 axet$ git pull
> Already up-to-date.
> axet-laptop:123 axet$ git push
> To https://github.com/axet/common-bin.git
>  ! [rejected]        master -> master (non-fast-forward)
> error: failed to push some refs to 'https://github.com/axet/common-bin.git'
> To prevent you from losing history, non-fast-forward updates were rejected
> Merge the remote changes (e.g. 'git pull') before pushing again.  See the
> 'Note about fast-forwards' section of 'git push --help' for details.
> axet-laptop:123 axet$
>
>
> it tries to push local master to remote common/master which is not correct.

This is controlled by the 'push.default' variable, the docs for which are as follows:

  push.default::
  	Defines the action git push should take if no refspec is given
  	on the command line, no refspec is configured in the remote, and
  	no refspec is implied by any of the options given on the command
  	line. Possible values are:
  +
  * `nothing` - do not push anything.
  * `matching` - push all matching branches.
    All branches having the same name in both ends are considered to be
    matching. This is the default.
  * `upstream` - push the current branch to its upstream branch.
  * `tracking` - deprecated synonym for `upstream`.
  * `current` - push the current branch to a branch of the same name.

The default of 'matching' pushes X to remotename/X, which is what you are seeing. You can either set it to 'upstream' or specify the target explicitly, as in

  git push common common:master
-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Andreas Schwab· Jan 12, 2012, 14:36 UTC · re: Alexey Kuznetsov · lore

Re: clone bug

Alexey Kuznetsov <kuznetsov.alexey@gmail.com> writes:
Show 8 quoted lines
> axet-laptop:123 axet$ git branch
> * master
> # git remote add common https://github.com/axet/common-bin.git
> # git fetch common
> From https://github.com/axet/common-bin
>  * [new branch]      master     -> common/master
>
> ?? already strange master (local) to the remote common/master

The message means: the remote ref 'refs/heads/master' is stored locally in 'refs/remotes/common/master'.

> axet-laptop:123 axet$ git push
> To https://github.com/axet/common-bin.git
>  ! [rejected]        master -> master (non-fast-forward)

"git push" is the same as "git push common" ('common' is the current branch's remote). Since branch.master.push is not defined this then uses the push.default config option to determine the action. The default is 'matching', which means that local branch names are matched against remote branch names. Local branch master matches remote branch master. Note that this disregards the setting for branch.master.upstream. If you do not want that you should set push.default to 'upstream'.

See the examples in git-push(1) for more details.
Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

← back to recent threads