Git 远程仓库

应用情景1:先创建远程仓库 remote_repo(空的),再创建本地仓库 local_repo,然后关联远程仓库。

应用情景2:已有远程仓库 remote_repo(可以非空),本地直接克隆远程仓库。

情景1:

1、先创建远程空仓库 remote_repo,获取URL:

  SSH:git@github.com:xxx/helloworld.git

  HTTPS:https://github.com/xxx/helloworld.git

  这里是在 GitHub 上面创建的远程仓库,两种 URL 任选其一使用即可,其中xxx代表用户名,具体区别不解释。

2、如果此时还没有本地仓库,先创建本地仓库 local_repo 然后关联远程仓库。本地仓库名称可随意取,一般与远程仓库同名比较好:

mkdir local_repo
cd local_repo
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@gitlab:xxx/remote_repo.git
git push -u origin master

3、如果已经有本地仓库  local_repo 了,此时需要做的就是关联远程仓库:

cd local_repo
git remote add origin git@gitlab:xxx/remote_repo.git
git push -u origin master

情景2:

1、直接获取远程仓库URL,克隆到本地,本地仓库名称默认与远程仓库同名:

 git clone git@github.com:xxx/remote_repo.git
原文地址:https://www.cnblogs.com/litmmp/p/5221505.html