我想从新的远程存储库跟踪远程主分支.两者都已存在.
我怎么用git来解决这个问题?我似乎无法做对.我试过了:
git remote add otherRepo git://...
git branch -t myTrack otherRepo/master
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误:
fatal: Not a valid object name: 'otherRepo/master'.
Chr*_*sen 12
正如评论所述:git remote add otherRepo …只配置遥控器,它不会从中获取任何东西.您需要运行git fetch otherRepo以获取远程存储库的分支,然后才能基于它们创建本地分支.
(回应OP的进一步评论)
如果您只想跟踪远程存储库中的单个分支,则可以重新配置远程的fetch属性(remote.otherRepo.fetch).
# done as a shell function to avoid repeating the repository and branch names
configure-single-branch-fetch() {
git config remote."$1".fetch +refs/heads/"$2":refs/remotes/"${1}/${2}"
}
configure-single-branch-fetch "$remoteName" "$branch"
# i.e. # configure-single-branch-fetch otherRepo master
Run Code Online (Sandbox Code Playgroud)
在此之后,git fetch otherRepo只会将远程存储库的master分支提取到otherRepo/master本地存储库中的"远程跟踪分支".
要清理其他"远程跟踪分支",您可以将它们全部删除并重新获取所需的那个,或者您可以有选择地删除所有这些除了您想要的那个:
git for-each-ref --shell --format='git branch -dr %(refname:short)' refs/remotes/otherRepo | sh -nv
# remove the -nv if the commands look OK, then
git fetch otherRepo
# OR
git for-each-ref --shell --format='test %(refname:short) != otherRepo/master && git branch -dr %(refname:short)' refs/remotes/otherRepo | sh -nv
# remove the -nv if the commands look OK
Run Code Online (Sandbox Code Playgroud)
如果您决定要跟踪多个远程分支,而不是所有远程分支,则可以使用多个获取配置(使用git config --add remote."$remoteName".fetch …或git config --edit直接复制和编辑存储库配置文件中的行).
如果您还想避免从远程获取标记,请配置远程的tagopt属性(remote.otherRepo.tagopt).
git config remote."$remoteName".tagopt --no-tags
# i.e. # git config remote.otherRepo.tagopt --no-tags
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6418 次 |
| 最近记录: |