Skip to content

Instantly share code, notes, and snippets.

@veritymissed
Last active June 3, 2019 04:09
Show Gist options
  • Save veritymissed/a2ee2a302b92ac2e96be6eb0225a4e49 to your computer and use it in GitHub Desktop.
Save veritymissed/a2ee2a302b92ac2e96be6eb0225a4e49 to your computer and use it in GitHub Desktop.
git remote 的相關用法

git remote 相關用法

remote -v

使用 git remote -v 列出現在目錄的所有遠端repository以及url設定

github	[email protected]:veritymissed/RESTful-API-server.git (fetch)
github	[email protected]:veritymissed/RESTful-API-server.git (push)
wavenet	ssh://[email protected]:10022/veritymissed/Cytac.git (fetch)
wavenet	ssh://[email protected]:10022/veritymissed/Cytac.git (push)

remote add

git remote add REMOTE_NAME new_url

在本機新增一個遠端repository名為 REMOTE_NAME,url為 new_url

Ex.

git remote add bitbucket [email protected]:veritymissed/Cytac.git

然後用 git remote -v 查看

...
bitbucket	[email protected]:veritymissed/Cytac.git (fetch)
bitbucket	[email protected]:veritymissed/Cytac.git (push)
github	[email protected]:veritymissed/RESTful-API-server.git (fetch)
...

remote set-url

git remote set-url REMOTE_NAME new_url

REMOTE_NAME 這個遠端repository的url改為 new_url

Ex.

執行 git remote set-url github [email protected]:veritymissed/Cytac.git

然後用 git remote -v 查看

...
github	[email protected]:veritymissed/Cytac.git (fetch)
github	[email protected]:veritymissed/Cytac.git (push) //已更新為Cytac.git
wavenet	ssh://[email protected]:10022/veritymissed/Cytac.git (fetch)
...

remote rename

git remote rename OLD_REMOTE_NAME NEW_REMOTE_NAME

OLD_REMOTE_NAME 這個遠端repository的名稱改為 NEW_REMOTE_NAME

Ex.

執行 git remote rename bitbucket bitfuckit

然後用 git remote -v 查看

bitfuckit	[email protected]:veritymissed/Cytac.git (fetch)//改成bitfuckit了
bitfuckit	[email protected]:veritymissed/Cytac.git (push)
github	[email protected]:veritymissed/Cytac.git (fetch)
github	[email protected]:veritymissed/Cytac.git (push)
wavenet	ssh://[email protected]:10022/veritymissed/Cytac.git (fetch)
wavenet	ssh://[email protected]:10022/veritymissed/Cytac.git (push)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment