Search code examples
gitgithooksgit-push

How to copy one branch with commit history to another new repo?


I would like to clone one branch from git repo A to new git repo B. Prefer to include all commits history.

Everything is OK following http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/. But when I try to push to remote, errors happened.

remote: ERROR: invalid comitter email: someone@hehe.com
...
remote: valid email addresses:
...
remote: error: hook declined to update refs/heads/mybranch
To ssh://git@git.internal/myrepo.git
 ! [remote rejected] mybranch -> mybranch (hook declined)
error: failed to push some refs to 'ssh://git@git.internal/myrepo.git'

I know that all the past commits were done by another person, who is not in the list of valid email addresses any more. How to ignore this kind of verification? Is there any other way to do this?

UPDATE

Asked our admin to change the remote settings. Now everything works.


Solution

  • You should ignore the hooks:

    git push --no-verify
    

    from the git-push documentation:

    --[no-]verify Toggle the pre-push hook (see githooks[5]). The default is --verify, giving the hook a chance to prevent the push. With --no-verify, the hook is bypassed completely.

    EDIT as noted by @torek, the tag [remote rejected] indicates that the problem comes from the remote. So setting flags locally won't help. You need to look at the settings on your git.internal server.