①. 远程仓库操作
命令名称 | 作用 |
git remote -v | 查看当前所有远程地址别名 |
git remote add 别名 远程地址 | 起别名添加远程仓库到本地 |
git push 别名 分支 | 推送本地分支上的内容到远程仓库 |
git clone 远程地址 | 将远程仓库的内容克隆到本地 |
git pull 远程库地址别名 远程分支名 | 将远程仓库对于分支最新内容拉下来后与当前本地分支直接合并 |
②. 查看远程仓库 git remote -v
- ①. 如果想查看已经配置的远程仓库服务器,可以运行 git remote (git remote -v) 命令。 它会列出指定的每一个远程服务器的简写
- ②. 如果已经克隆了远程仓库,那么至少应该能看到 origin,这是 Git 克隆的仓库服务器的默认名字
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git remote -v Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git remote Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git remote add git-demo https://github.com/Tz845195485/git-demo.git Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git remote git-demo Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git remote -v git-demo https://github.com/Tz845195485/git-demo.git (fetch) git-demo https://github.com/Tz845195485/git-demo.git (push) Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
③. 添加远程仓库 git remote add 别名 url
- 运行(git remote add 分支别名 远程地址 )添加一个新的远程Git仓库
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git remote add git-demo https://github.com/Tz845195485/git-demo.git Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git remote git-demo Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master) $ git remote -v git-demo https://github.com/Tz845195485/git-demo.git (fetch) git-demo https://github.com/Tz845195485/git-demo.git (push) Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
④. 从远程克隆 git clone url
①. 如果你想获得一份已经存在了的 Git 仓库的拷贝,这时就要用到 git clone 命令。 Git 克隆的是该 Git 仓库服务器上的几乎所有数据(包括日志信息、历史记录等),而不仅仅是复制工作所需要的文件。 当你执行 git clone 命令的时候,默认配置下远程 Git 仓库中的每一个文件的每一个版本都将被拉取下来。
git clone [url] (如果你设置的仓库是公开的,那么clone是不需要密码的)
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/rep03 $ git clone git://github.com/Tz845195485/git-demo.git Cloning into 'git-demo'... remote: Enumerating objects: 22, done. remote: Counting objects: 100% (22/22), done. remote: Compressing objects: 100% (9/9), done. remote: Total 22 (delta 6), reused 22 (delta 6), pack-reused 0 Receiving objects: 100% (22/22), done. Resolving deltas: 100% (6/6), done. Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/rep03
②. 如果你想克隆指定分支: git clone -b 分支名字 url
$ git clone -b TANGZHI https://gitee.com/tangzhi520/git-demo2.git Cloning into 'git-demo2'... remote: Enumerating objects: 26, done. remote: Counting objects: 100% (26/26), done. remote: Compressing objects: 100% (10/10), done. remote: Total 26 (delta 4), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (26/26), done. Resolving deltas: 100% (4/4), done. Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/rep07 $ cd git-demo2/ Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/rep07/git-demo2 (TANGZHI) $ git branch -a * TANGZHI remotes/origin/HEAD -> origin/master remotes/origin/TANGZHI remotes/origin/master Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/rep07/git-demo2 (TANGZHI)