6

There are a lot of answers stating that git 1.9 removes limitations of shallow clones. Nevertheless, I'm using 2.6.1 and still having the following basic issue:

First, I create an empty repo somewhere:

cd /tmp
mkdir target
cd target
git init

Then, I shallow clone some repo and add the above repo as remote:

cd /tmp
git clone --depth 1 git@github.com:muennich/urxvt-perls.git
cd urxvt-perls
git remote add target /tmp/target

Finally, I push this repo to the remote:

git push target master

But then I get:

! [remote rejected] master -> master (shallow update not allowed)
error: failed to push some refs to '/tmp/target'

What am I missing here?

memeplex
  • 2,297
  • 27
  • 26
  • If you are interested in gitlab allowing this check https://gitlab.com/gitlab-org/gitlab-ce/issues/3033. – memeplex Dec 31 '15 at 21:13
  • look at this [remote-rejected-shallow-update-not-allowed-after-changing-git-remote-url](http://stackoverflow.com/a/28985327/2206581) – hisland Mar 06 '17 at 05:06

4 Answers4

7

I'm answering my own question.

I tried going the other way around and adding urxvt-perls as a remote for target, then fetching from there. This fails because of the same reason but led me closer to a solution. From the git-fetch man:

  --update-shallow
       By default when fetching from a shallow repository, git fetch
       refuses refs that require updating .git/shallow. This option
       updates .git/shallow and accept such refs.

Now, using this option allows the shallow fetch. So the previous question becomes: Is it possible to specify that --update-shallow behavior while pushing? Well, there is an option for that:

receive.shallowupdate
    If set to true, .git/shallow can be updated when new refs require
    new shallow roots. Otherwise those refs are rejected.

I'm still trying to set this in github and the likes, though.

memeplex
  • 2,297
  • 27
  • 26
5
git fetch --unshallow

git push target master -f
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Roman Kuntyi
  • 51
  • 1
  • 1
2

Use git merge --squash.

If your remote is shallow and you want to merge from it, compress that merge into a single commit without the need to copy a history of commits (which shallow refs hide).

Community
  • 1
  • 1
Enrico Tiongson
  • 400
  • 4
  • 5
0

Well on Linux repo server... this

git config --local --add receive.shallowUpdate true

resulted in this being added to the repo config file.

[receive]
    shallowUpdate = true

So maybe if you can add that to the repo config file.

NOYB
  • 625
  • 8
  • 14