查看远程仓库在本地的名字
$ git remote
origin
查看远程仓库与其对应的 URL
$ git remote -v
origin https://github.com/schacon/ticgit (fetch)
origin https://github.com/schacon/ticgit (push)
添加远程仓库
$ git remote
origin
$ git remote add pb https://github.com/paulboone/ticgit
$ git remote -v
origin https://github.com/schacon/ticgit (fetch)
origin https://github.com/schacon/ticgit (push)
pb https://github.com/paulboone/ticgit (fetch)
pb https://github.com/paulboone/ticgit (push)
现在你可以在命令行中使用字符串 pb 来代替整个 URL。 例如,如果你想拉取 Paul 的仓库中有但你没有的信息,可以运行 git fetch pb:
$ git fetch pb
remote: Counting objects: 43, done.
remote: Compressing objects: 100% (36/36), done.
remote: Total 43 (delta 10), reused 31 (delta 5)
Unpacking objects: 100% (43/43), done.
From https://github.com/paulboone/ticgit
* [new branch] master -> pb/master
* [new branch] ticgit -> pb/ticgit
查看某个远程仓库
$ git remote show origin
* remote origin
Fetch URL: https://github.com/schacon/ticgit
Push URL: https://github.com/schacon/ticgit
HEAD branch: master
Remote branches:
master tracked
dev-branch tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
远程仓库的重命名与移除
你可以运行 git remote rename 来修改一个远程仓库的简写名。 例如,想要将 pb 重命名为 paul,可以用 git remote rename 这样做:
$ git remote rename pb paul
$ git remote
origin
paul
移除一个远程仓库可以使用 git remote remove 或 git remote rm :
$ git remote remove paul
$ git remote
origin
修改远程仓库地址
git remote set-url origin [url]
在配置文件中查看和修改
进入项目根目录,配置文件在.git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = https://github.com/schacon/ticgit.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "pb"]
url = https://github.com/paulboone/ticgit.git
fetch = +refs/heads/*:refs/remotes/pb/*
[gui]
wmstate = normal
geometry = 841x483+182+182 189 218
本文详细介绍了Git如何查看、添加、重命名及移除远程仓库,包括`git remote`的各种命令,如`git remote show`、`git remote add`、`git remote rename`和`git remote remove`。此外,还展示了如何修改远程仓库URL以及查看和修改配置文件。
553

被折叠的 条评论
为什么被折叠?



