我有一个文件夹备份在一个公共的git存储库(git1
存储库(中。
我们现在只是保留文件的最终版本的存储库,并为工作文件(git2
存储库(设置单独的 Git 存储库。
希望这样事情会保持清洁。git 存储库是完全独立的,而不是相同的分支。
我遇到的问题是我无法弄清楚我的工作文件夹备份到哪个 Git 存储库是如何更改的。
我创建了一个新文件夹,然后将旧文件夹的内容复制到这个新文件夹中(cp
命令(。现在,当我执行git推送并输入新git存储库(git2
存储库(的地址时,它会给出失败消息
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/git2repo.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
当我这样做git status
我得到:
On branch master
Your branch is up to date with 'origin/master'.
当我做git remote -v
:
origin https://github.com/git1repo.git (fetch)
origin https://github.com/git1repo.git (push)
它为fetch
和push
提供了与我们设置的上一个地址(git1
repo(相同的 git 地址 - 而不是我现在试图推送的新地址(git2
reppo((。
不知道如何更改文件夹被推送到的位置,我显然不想更改git1
存储库中的任何内容。
任何时候你想推送,最好推送到一个裸存储库,这是一个没有任何文件(没有工作树(的存储库,只有 .git 内容。
git init --bare dest
cd /path/to/repo/to/backup
git remote add backup /path/to/bare/repo/dest
git push --mirror backup
更一般地说,我通过为我的 git push 命令指定存储库"备份"来更改推送位置:请参阅git push <repository>
。
如果需要修复名为"origin"的现有远程背后的 URL,就像 OP 所做的那样,请考虑:
git remote set-url origin https://github.com/git2repo.git
git remote -v
backup https://github.com/git2repo.git (fetch)
backup https://github.com/git2repo.git (push)
origin https://github.com/git2repo.git (fetch)
origin https://github.com/git2repo.git (push)