背景:我正在使用 git。我通常会从其他存储库中分叉,并时不时地做出贡献。我经常切换工作机器 - 并且还会删除远程存储库的本地克隆。当我想恢复工作时,我需要执行以下操作:
- git 克隆https://github.com/example-upstream/repo
- cd 仓库
- git 远程重命名源上游
- git 远程添加原点https://github.com/example-fork/repo
- git 获取源地址
- git push origin # 将主分支从上游推送到原点
对于步骤 6,有git-town sync
。 我检查了中心和生长素。
答案1
解决方案是使用gh repo clone <fork-url>
:
gh repo clone https://github.com/example-fork/repo
这将完成步骤 1 至 5 的所有操作:
$ gh repo clone https://github.com/example-fork/repo
Cloning into 'repo'...
remote: Enumerating objects: 410, done.
remote: Counting objects: 100% (151/151), done.
remote: Compressing objects: 100% (73/73), done.
remote: Total 410 (delta 80), reused 139 (delta 78), pack-reused 259
Receiving objects: 100% (410/410), 79.42 KiB | 2.48 MiB/s, done.
Resolving deltas: 100% (212/212), done.
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 16 (delta 9), reused 15 (delta 9), pack-reused 0
Unpacking objects: 100% (16/16), 4.33 KiB | 119.00 KiB/s, done.
From github.com:example-upstream/repo
* [new branch] master -> upstream/master
* [new tag] release-2023.2 -> release-2023.2
! Repository example-upstream/repo set as the default repository. To learn more about the default repository, run: gh repo set-default --help
使用 在 Windows 上安装它winget install --id GitHub.cli
。