假设我在git.fedorahosted.org上有一个存储库,我想将它克隆到我在github的帐户中,除了fedorahosted上更"官方"的回购之外,还有我自己的游乐场.最初复制它的步骤是什么?在github中有一个很好的"fork"按钮,但由于显而易见的原因,我无法使用它.
我如何跟踪fedorahosted repo中的变化到github one?
tro*_*skn 699
git remote rename origin upstream
git remote add origin URL_TO_GITHUB_REPO
git push origin master
现在你可以像任何其他github repo一样使用它.要从上游提取补丁,只需运行即可git pull upstream master && git push origin master
.
mob*_*mob 100
这个问题有一个删除的答案,它有一个有用的链接:https: //help.github.com/articles/duplicating-a-repository
要点是
0. create the new empty repository (say, on github)
1. make a bare clone of the repository in some temporary location
2. change to the temporary location
3. perform a mirror-push to the new repository
4. change to another location and delete the temporary location
Run Code Online (Sandbox Code Playgroud)
OP的例子:
在您的本地计算机上
$ cd $HOME
$ git clone --bare https://git.fedorahosted.org/the/path/to/my_repo.git
$ cd my_repo.git
$ git push --mirror https://github.com/my_username/my_repo.git
$ cd ..
$ rm -rf my_repo.git
Run Code Online (Sandbox Code Playgroud)
ken*_*orb 40
要将现有的仓库推送到不同的仓库,您需要:
首先克隆原始回购.
git clone https://git.fedorahosted.org/cgit/rhq/rhq.git
Run Code Online (Sandbox Code Playgroud)将克隆的源推送到新的存储库:
cd rhq
git push https://github.com/user/example master:master
Run Code Online (Sandbox Code Playgroud)你可以master:master
改成source:destination
分支.
如果要推送特定的提交(分支),那么执行:
在原始仓库中,创建并签出新分支:
git checkout -b new_branch
Run Code Online (Sandbox Code Playgroud)选择并重置为您要开始的点:
git log # Find the interesting hash
git reset 4b62bdc9087bf33cc01d0462bf16bbf396369c81 --hard
Run Code Online (Sandbox Code Playgroud)
或者,选择commit by git cherry-pick
以附加到现有HEAD中.
然后推送到您的新回购:
git push https://github.com/user/example new_branch:master
Run Code Online (Sandbox Code Playgroud)
如果您正在变基础,请使用-f
强制推动(不推荐).运行git reflog
以查看更改历史记录.
Hai*_*Dog 13
你真的想简单地将你的本地存储库(带有本地分支机构等)推送到新的遥控器,还是你真的想要在新的遥控器上镜像旧遥控器(及其所有分支,标签等)?如果后者在这里是关于如何正确镜像git存储库的好博客.
我强烈建议您阅读博客中的一些非常重要的细节,但简短的版本是这样的:
在新目录中运行以下命令:
git clone --mirror git@example.com/upstream-repository.git
cd upstream-repository.git
git push --mirror git@example.com/new-location.git
Run Code Online (Sandbox Code Playgroud)
vm3*_*345 10
试试这个如何移动一个完整的Git存储库
使用以下命令在temp-dir目录中创建本地存储库:
git clone temp-dir
进入temp-dir目录.
要查看ORI中不同分支的列表,请执行以下操作:
git branch -a
Run Code Online (Sandbox Code Playgroud)使用以下命令检出要从ORI复制到NEW的所有分支:
git checkout branch-name
Run Code Online (Sandbox Code Playgroud)现在使用以下方法从ORI获取所有标记:
git fetch --tags
Run Code Online (Sandbox Code Playgroud)在执行下一步之前,请确保使用以下命令检查本地标记和分支:
git tag
git branch -a
Run Code Online (Sandbox Code Playgroud)现在使用以下命令清除指向ORI存储库的链接:
git remote rm origin
Run Code Online (Sandbox Code Playgroud)现在使用以下命令将本地存储库链接到新创建的新存储库:
git remote add origin <url to NEW repo>
Run Code Online (Sandbox Code Playgroud)现在使用以下命令推送所有分支和标记:
git push origin --all
git push --tags
Run Code Online (Sandbox Code Playgroud)您现在拥有ORI回购的完整副本.
小智 10
只需使用以下命令更改 GIT 存储库 URL 即可指向新存储库:
git remote set-url origin [new repo URL]
Run Code Online (Sandbox Code Playgroud)
例子: git remote set-url origin git@bitbucket.org:Batman/batmanRepoName.git
现在,推和拉都与新的 REPO 相关联。
然后像这样正常推送:
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
如果您有现有的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
Run Code Online (Sandbox Code Playgroud)
我找到了一个使用set-url的解决方案,它简洁易懂:
cd
进入本地计算机上的现有存储库(如果尚未克隆它,请先执行此操作)git remote set-url origin https://github.com/user/example.git
git push -u origin master
这帮助我将本地项目推送到 git 上的另一个存储库中
git push https://github.com/yourusername/yourgithubproject.git master:master
Run Code Online (Sandbox Code Playgroud)
这是一种手动方法git remote set-url origin [new repo URL]
:
git clone <old remote>
打开<repository>/.git/config
$ git config -e
Run Code Online (Sandbox Code Playgroud)
[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
Run Code Online (Sandbox Code Playgroud)
并更改远程(url 选项)
[remote "origin"]
url = <new remote>
fetch = +refs/heads/*:refs/remotes/origin/*
Run Code Online (Sandbox Code Playgroud)将存储库推送到 GitHub:git push
您还可以使用两个/多个遥控器。
小智 5
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
就是这样!
首先,在 Github 上创建您的存储库。然后将目录更改为已签出的源存储库 - 假设您想推送master
分支。您需要执行 5 个简单步骤:
git remote add origin2 https://github.com/user/example.git
git checkout master
git pull
git push origin2 master
git remote remove origin2
Run Code Online (Sandbox Code Playgroud)
这将创建本地存储库和新远程存储库之间的链接,签出并拉取源分支(以确保它具有最新的),然后推送当前分支,最后取消本地存储库与远程存储库的链接。
此后您的本地存储库将完好无损,您可以像以前一样使用它。如果需要推送多个分支,请根据需要多次重复checkout
- pull
-步骤,只需相应更改分支名称即可。push
归档时间: |
|
查看次数: |
328452 次 |
最近记录: |