There are two remote repositories as follows.
- original.git: The original bare repository.
- mirror.git: A mirror repository cloned with
git clone --mirror original.git
.
Pushing refs from the mirror to the original remote using git push --mirror
works as expected. However, when refspec
(e.g. branch name) is combined with git-push
, Git tries to delete all the other branches except for the specified one, from both original and mirror repositories.
- Why does Git try to delete other branches?
- How can I prevent from deleting remote branches in cases where
receive.denyDeletes
is not set in remote repositories? (I just deleted remote branches by mistake.)
Note: I'm using git v2.18.0
now, and as far as I know, git push --mirror <repo> <refsepc>
is not allowed in older versions such as git v1.7.1
.
bash-4.1$ cd mirror.git/
bash-4.1$ git branch
* master
new_branch
bash-4.1$ git config --list | grep remote
remote.origin.url=/user/han/git/original.git/
remote.origin.fetch=+refs/*:refs/*
remote.origin.mirror=true
bash-4.1$ git push --mirror
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 16 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 280 bytes | 280.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /user/han/git/original.git/
* [new branch] new_branch -> new_branch
bash-4.1$ git push origin master
To /user/han/git/original.git/
- [deleted] new_branch