6

Is it possible somehow to set up a git repository that works as a usual --mirror for pulling into it, but without forcing when pushing from it to another repo?

gsakkis
  • 1,569
  • 1
  • 15
  • 24
  • http://superuser.com/questions/276079/disable-specific-git-commands-in-a-particular-repository - Might work for you? – sjakubowski Aug 16 '13 at 01:35
  • What is --mirror pushing that you want to push? If you are looking for tags and remotes you should be able to push those with a refspec. – andygavin Aug 16 '13 at 17:57

3 Answers3

4

You can just add --no-force to disable the forcing behavior like so:

git push --mirror --no-force

This will disable non-fast-forward updates (tested with git 1.8.0.2).

Matthijs P
  • 1,144
  • 1
  • 9
  • 17
  • 2
    Not seeing this behavior in `1.8.4` nor is `--no-force` documented in the man page for `git-push`. Additionally, there are no mentions of the removal of a `--no-force` option in the release notes between `1.8.0.2` and `1.8.4`. – bloudermilk Sep 04 '13 at 23:49
  • 1
    Interestingly, the --no-force option has no effect if the remote has the "mirror" option set to true in the local config. Once I removed the "mirror" option from the config and set `--mirror` from the command line as shown above, everything worked as advertised. My git version is `1.8.4`. – bloudermilk Sep 04 '13 at 23:56
3

I'd like to do a git push --mirror that will fail if a non-fast forward update is required.

A git push --mirror should fail if the upstream repo has its config set to receive.denyNonFastForwards true:

git config man page:

receive.denyNonFastForwards

If set to true, git-receive-pack will deny a ref update which is not a fast-forward.
Use this to prevent such an update via a push, even if that push is forced.
This configuration variable is set when initializing a shared repository.

That means you wouldn"t have to "reproduce what --mirror" does: you could simply use it, and still have that push fail if any non-fastforward merge is involved.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Is there maybe a way to reproduce what --mirror does with other options?

Some of what mirror does can be performed using a number of pushes:

git push <remote> --all  # push all branches
git push <remote> --tags # push all tags
git push <remote> refs/remotes/* #push the remote refs
andygavin
  • 2,784
  • 22
  • 32