现有的git(私有远程)repo已经存在.无法与以前的开发人员取得联系



想象一下。你刚得到一个新的副业。您被授予对应用程序的root访问权限。您通过ssh进入服务器。您执行:

git status

你会看到:

Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified:   .htaccess
modified:   office/.htaccess
modified:   office/error_log
modified:   office/wp-admin/error_log
modified:   template/default/javascript.js
modified:   www2/.htaccess
Untracked files:
(use "git add <file>..." to include in what will be committed)
public_html/
no changes added to commit (use "git add" and/or "git commit -a")

"好的";你自己想。然后运行一个:

git config --list

你看到

core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:somecoolguy/somecoolproject.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

然后,您访问github,查看somecoolgoy的项目,并注意到它是私有的。

您希望将回购转移到另一个git远程位置,维护历史记录,并且不会丢失任何未提交的更改,这样您就可以开始处理此项目,并对自己的回购拥有完全所有权。。。

你是做什么的?

即使somecoolgoy在Github中的帐户是私有的,您在服务器中也有git存储库的完整副本(您的分支是最新的'origin/master')。您应该能够在您的帐户下的Github中创建一个新的存储库,并将其添加为另一个remote,在那里您可以推送git历史记录。

git remote add anotherorigin git@github.com:myaccount/somecoolproject.git

请注意,这个遥控器指向的是你的帐户,而不是某个酷家伙的帐户。

如果你不想摆弄SSH密钥(因为服务器中的密钥可能属于某个酷家伙),你可以使用https链接新的来源,在推送时需要你的Github凭据:

git remote add anotherorigin https://github.com/myaccount/somecoolproject.git

一旦这样做,就足以将存储库推送到新的远程服务器。如果你不想丢失尚未提交的更改,你可以在推送之前提交未提交的文件:

git add .
git commit -m "New commit"
git push anotherorigin master

最新更新