[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 获得的分支是同样的了。

相关文章
相关标签/搜索