假设我在 git.fedorahosted.org 上有一个代码库,我想将其克隆到我的github帐户中,以便于在fedorahosted上的官方代码之外拥有自己的“游乐场”。 最初复制这个仓库需要哪些步骤呢? 在github中有这个不错的“fork”按钮,但出于明显的原因我无法使用它。
如何跟踪fedorahosted代码库的更改并同步到github的代码库中?
假设我在 git.fedorahosted.org 上有一个代码库,我想将其克隆到我的github帐户中,以便于在fedorahosted上的官方代码之外拥有自己的“游乐场”。 最初复制这个仓库需要哪些步骤呢? 在github中有这个不错的“fork”按钮,但出于明显的原因我无法使用它。
如何跟踪fedorahosted代码库的更改并同步到github的代码库中?
1- 删除与远程仓库的所有连接: 在项目文件夹内:
git rm .git
(从本地仓库中删除所有数据)git status
(必须指出它没有与任何东西连接,类似于错误)2- 链接到新的远程仓库
git init
(启动本地仓库)git remote add origin urlrepository.git
(链接到远程仓库)git remote -v
(确认已经连接到远程仓库)3- 将更改添加到本地仓库并推送到远程仓库
git pull
或 git pull origin master --allow-unrelated-histories
(如果本地和远程仓库的Git历史记录不同,则需要执行此步骤)git add .
git commit -m" Message "
git push -u origin master
就是这样了!
这里有一种手动的方法来执行 git remote set-url origin [新仓库URL]
:
git clone <old remote>
Open <repository>/.git/config
$ git config -e
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = <old remote>
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
and change the remote (the url option)
[remote "origin"]
url = <new remote>
fetch = +refs/heads/*:refs/remotes/origin/*
Push the repository to GitHub: git push
您还可以使用两个或多个远程仓库/多个远程仓库。
从命令行推送现有仓库
git remote add origin https://github.com/AyadiAkrem/teachandgo.git
git branch -M main
git push -u origin main
cd old-repo/
命令并获取所有新更改git push -u https://github.com/[用户名]/new-repo.git main -f
https://github.com/[用户名]/new-repo.git
克隆到本地环境中我也遇到了同样的问题。
在我的情况下,由于我在本地机器上拥有原始存储库,我已经将其复制到一个新文件夹中,没有任何隐藏文件(.git,.gitignore)。
最后,我向新创建的文件夹添加了.gitignore文件。
然后,我使用本地路径创建并添加了新的存储库(在我的情况下使用GitHub Desktop)。