[Git] 將本地分支與遠程分支關聯

.git

.ssh

.fetch

.spa

.code

在本地工程中添加Git,並將其與遠程的空庫關聯起來,只需以下幾步。blog

1. 建立空庫rem

$ git init
Initialized empty Git repository in D:/workspace/shop/.git/

2. 添加遠程倉庫it

$ git remote add origin ssh://user@192.168.1.2:29418/prj/shop

3. 獲取倉庫中的分支ast

$ git fetch
remote: Counting objects: 2, done
remote: Finding sources: 100% (2/2)
remote: Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
From ssh://192.168.1.2:29418/prj/shop
 * [new branch]      master     -> origin/master

$ git branch -a
  remotes/origin/master

4. 建立本地分支class

$ git pull origin master
From ssh://192.168.1.2:29418/prj/shop
 * branch            master     -> FETCH_HEAD

$ git branch -a
* master
  remotes/origin/master

5. 將本地分支與遠程分支關聯起來

$ git branch --set-upstream-to=origin/master master
Branch 'master' set up to track remote branch 'master' from 'origin'.

完成。

通過上述步驟操做後,操做此分支與操做直接經過 git clone 獲得的分支是同樣的了。

相關文章
相關標籤/搜索