GIT05_远程仓库操作查看添加克隆clone移除rm拉取pull推送push
Posted TZ845195485
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GIT05_远程仓库操作查看添加克隆clone移除rm拉取pull推送push相关的知识,希望对你有一定的参考价值。
文章目录
①. 远程仓库操作
命令名称 | 作用 |
---|---|
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)
⑤. 移除无效的远程仓库 git remote rm
- 如果因为一些原因想要移除一个远程仓库 ,可以使用 git remote rm
注意:此命令只是从本地移除远程仓库的记录,并不会真正影响到远程仓库
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/rep03/git-demo (master)
$ git remote rm origin
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/rep03/git-demo (master)
$ git remote -v
⑥. 从远程仓库中抓取代码 git fetch
- git fetch 是从远程仓库获取最新版本到本地仓库,不会自动merge
不会自动merge:就是你使用git fetch origin master 没有代码拉去下来
⑦. 从远程仓库拉取代码 git pull 分支别名 分支名称
- git pull 是从远程仓库获取最新版本并merge到本地仓库
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/rep03/git-demo (master)
$ git remote add git-demo https://github.com/Tz845195485/git-demo.git
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/rep03/git-demo (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/rep03/git-demo (master)
$ git pull git-demo master
From https://github.com/Tz845195485/git-demo
* branch master -> FETCH_HEAD
* [new branch] master -> git-demo/master
Already up to date.
⑧. 推送到远程仓库 git push
- ①. 当你想分享你的代码时,可以将其推送到远程仓库。 命令形式:git push [分支别名] [branch-name]
Administrator@SD-20191128LXMQ MINGW64 /d/gitRepos/repo1 (master)
$ git push git-demo master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 284 bytes | 284.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/Tz845195485/git-demo.git
0c17f90..5ed2aaa master -> master
- ②. 此时发现已将我们master分支上的内容推送到GitHub创建的远程仓库
以上是关于GIT05_远程仓库操作查看添加克隆clone移除rm拉取pull推送push的主要内容,如果未能解决你的问题,请参考以下文章