需要将本地文件夹git repo更改为另一个不同的git repo

时间:2018-09-25 04:16:23

标签: git github

我有一个备份在公用git存储库(git1存储库)中的文件夹。
现在,我们做了一个回购,以保留文件的最终版本,并为工作文件设置了单独的Git存储库(git2回购)。
希望这样可以使事情保持清洁。 git存储库是完全独立的,而不是相同的分支。

我遇到的问题是我无法弄清楚如何更改我的工作文件夹备份到的Git存储库。
我创建了一个新文件夹,然后将旧文件夹的内容复制到了这个新文件夹中(cp命令)。现在,当我执行git push并放置新git repo(git2 repo)的地址时,它会显示一条失败消息

! [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)

它为fetchpush提供了与我们设置的上一个相同的git地址(git1回购)-不是我要推送到的新地址({git2回购))。

不确定如何更改文件夹的推送位置,我显然不想更改git1存储库中的任何内容。

1 个答案:

答案 0 :(得分:0)

每当您要推送时,最好将其推送到裸仓库,即没有任何文件(没有工作树)的仓库 ,只有.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命令中指定存储库“ backup”来更改 where 以进行推送:请参见git push <repository>

如果像OP那样需要在现有远程名为“ origin”的远程站点后面修复URL,请考虑:

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)
相关问题