git remote
基本使用
git是一個分佈式代碼管理工具,所以可以支持多個倉庫,在git裏,服務器上的倉庫在本地稱之爲remote
。
直接clone
一個倉庫:
$: git clone [email protected]:projects/search.git
另外一種clone
方式:
# 創建目錄初始化本地倉庫 $: mkdir search && cd search $: git init # 添加遠程倉庫路徑 $: git remote add github [email protected]:yyfrankyy/search.git # 實際上,pull 就是 fetch + merge $: git pull github --all --tags
把工作目錄遷移到github上面:
$: git remote add github [email protected]:yyfrankyy/search.git $: git push github --all --tags
顯示所有的遠程倉庫
$: git remote -v origin [email protected]:projects/search.git (fetch) origin [email protected]:projects/search.git (push) github [email protected]:yyfrankyy/search.git (fetch) github [email protected]:yyfrankyy/search.git (push)
重命名遠程倉庫
$: git remote rename github gh $: git remote origin gh
刪除遠程倉庫
$: git remote rm github $: git remote origin
從遠程倉庫抓取數據,更新本地倉庫:
$: git fetch origin remote: Counting objects: 58, done. remote: Compressing objects: 100% (41/41), done. remote: Total 44 (delta 24), reused 1 (delta 0) Unpacking objects: 100% (44/44), done. From git://search.ued.taobao.net:projects/search.git * [new branch] product -> origin/product
查看遠程倉庫信息,可用於跟蹤別人的push
:
$: git remote show origin * remote origin Fetch URL: [email protected]:projects/search.git Push URL: [email protected]:projects/search.git HEAD branch: master Remote branches: master tracked p4popt tracked prepub tracked product tracked Local branches configured for 'git pull': master merges with remote master p4popt merges with remote p4popt prepub merges with remote prepub product merges with remote product Local refs configured for 'git push': master pushes to master (up to date) p4popt pushes to p4popt (up to date) prepub pushes to prepub (up to date) product pushes to product (up to date)