Created
December 5, 2011 19:10
-
-
Save tyru/1434828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
# テストのためのディレクトリ作る | |
[ -d test ] && rm -rf test | |
mkdir test && cd test | |
# nonbare-repo作る | |
setup_nonbare_repo() { | |
touch foo | |
git add foo | |
git commit -m 'initial commit' | |
} | |
git init nonbare-repo | |
(cd nonbare-repo && setup_nonbare_repo) | |
# bare-repo作る | |
git clone --bare nonbare-repo bare-repo | |
# local-repo作る | |
git clone bare-repo local-repo | |
# nonbare-repoに変更加えてbare-repoにpush (これは当然成功する) | |
update_bare_repo() { | |
touch bar | |
git add bar | |
git commit -m 'add bar' | |
git remote add bare ../bare-repo | |
git push bare master | |
} | |
(cd nonbare-repo && update_bare_repo) | |
# bare-repoからlocal-repoにpush (これがshim0muraさんのしたいこと) | |
push_to_local_repo() { | |
git remote add local ../local-repo | |
# bareでないリポジトリの場合、他のリポジトリから更新を許すため | |
# 一旦local-repoでreceive.denyCurrentBranchをignoreにする必要がある。 | |
# これをしないと末尾のようなエラーが出る。 | |
(cd ../local-repo && git config receive.denyCurrentBranch ignore) | |
# やっとpushできるようになる | |
git push local master | |
# コミットは追加されるがワーキングツリーの状態は変わらないので | |
# git reset --hardして強制的にワーキングツリーを最新の状態にする。 | |
(cd ../local-repo && git reset --hard) | |
} | |
(cd bare-repo && push_to_local_repo) | |
# remote: error: refusing to update checked out branch: refs/heads/master | |
# remote: error: By default, updating the current branch in a non-bare repository | |
# remote: error: is denied, because it will make the index and work tree inconsistent | |
# remote: error: with what you pushed, and will require 'git reset --hard' to match | |
# remote: error: the work tree to HEAD. | |
# remote: error: | |
# remote: error: You can set 'receive.denyCurrentBranch' configuration variable to | |
# remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into | |
# remote: error: its current branch; however, this is not recommended unless you | |
# remote: error: arranged to update its work tree to match what you pushed in some | |
# remote: error: other way. | |
# remote: error: | |
# remote: error: To squelch this message and still keep the default behaviour, set | |
# remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. | |
# To ../local-repo | |
# ! [remote rejected] master -> master (branch is currently checked out) | |
# error: failed to push some refs to '../local-repo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment