假设我在git.fedorahosted.org上有一个存储库,我想将其克隆到我在github的帐户中,以拥有自己的游乐场,而不是在fedorahosted上更“官方”的回购。 最初复制的步骤是什么? 在github中有一个漂亮的“fork”按钮,但我不能使用这个明显的原因。

我如何跟踪fedorahosting回购到github的变化?


当前回答

首先,在Github上创建你的回购。然后将目录更改为签出的源存储库—假设您想要推送主分支。你需要执行5个简单的步骤:

git remote add origin2 https://github.com/user/example.git
git checkout master
git pull
git push origin2 master
git remote remove origin2

这将在本地回购和新的远程之间创建链接,签出并拉出源分支(以确保它有最新的分支),然后推入当前分支,最后从远程断开本地回购的链接。

在此之后,您的本地回购将是完整的,您可以像以前一样使用它。如果需要推送多个分支,可以根据需要多次重复签出-拉-推步骤,只需相应地更改分支名称即可。

其他回答

我也遇到过同样的问题。

在我的例子中,由于我在本地机器中有原始的存储库,所以我在一个新文件夹中创建了一个副本,没有任何隐藏文件(。git, .gitignore)。

最后,我将.gitignore文件添加到新创建的文件夹中。

然后,我已经从本地路径创建并添加了新的存储库(在我的情况下使用GitHub Desktop)。

您真的想简单地将本地存储库(及其本地分支等)推到新的远程,还是真的想在新的远程上镜像旧的远程(及其所有分支、标记等)?如果是后者,这里有一个关于如何正确镜像git存储库的很棒的博客。

我强烈建议你阅读这篇博客,了解一些非常重要的细节,但简短的版本是这样的:

在一个新目录下运行这些命令:

git clone --mirror git@example.com/upstream-repository.git
cd upstream-repository.git
git push --mirror git@example.com/new-location.git

Visual studio 2022和默认的git扩展甚至不需要一行命令就可以完美地工作。

步骤1:进入git设置

步骤2:在git/azure中添加指向不同存储库的新原点

步骤3:现在你可以选择在git/azure的不同存储库中推送到新的原点

现在在新的存储库中有了一个新的分支

如果你有现有Git存储库:

cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.com/newproject
git push -u origin --all
git push -u origin --tags

要将你现有的回购变为不同的,你需要:

首先克隆原始的回购。 Git克隆https://git.fedorahosted.org/cgit/rhq/rhq.git 将克隆的源代码推到您的新存储库: cd rhq Git推送https://github.com/user/example master:master

您可以将master:master改为source:destination分支。


如果你想要推送特定的提交(分支),那么做:

On the original repo, create and checkout a new branch: git checkout -b new_branch Choose and reset to the point which you want to start with: git log # Find the interesting hash git reset 4b62bdc9087bf33cc01d0462bf16bbf396369c81 --hard Alternatively select the commit by git cherry-pick to append into existing HEAD. Then push to your new repo: git push https://github.com/user/example new_branch:master If you're rebasing, use -f for force push (not recommended). Run git reflog to see history of changes.