GIT使用-1.GIT常见命令学习
2017-10-19 16:49
519 查看
1.git clone
说明
克隆远端仓库中代码到本地仓库$ git clone <远端仓库地址> <本地目录名>
本地目录名是你设定的项目目录名,可选项,不设定会以默认名作为选项
举例
$ git clone https://github.com/hewin/machielearning-MLP.git MLP$ git clone https://github.com/hewin/machielearning-MLP.git
$ ls -al
total 0
drwxr-xr-x 5 chenwenxin staff 170 10 19 14:05 MLP
drwxr-xr-x 6 chenwenxin staff 204 10 19 13:57 machielearning-MLP
这两个语句会生成不同名词的文件夹,但是里面的内容是一样的。
2.git remote
说明
用来对远程主机进行的增、删、改、查操作增:git remote add <主机名> <远端库地址>
删:git remote rm <主机名>
查:git remote show <主机名> 用于查看远端主机,不加主机名会显示主机列表,加主机名会显示详细信息
改:git remote rename <原主机名> <新主机名>
3.git fetch
说明1
将远端仓库的代码下载到本地仓库,供后面使用,比如再新建一个分支或者是merge到某个分支git fecth <远程主机> <分支名>
示例1:git fetch不加其他内容,直接将所有的远端仓代码fetch到本地仓
$ git fetchFromhttps://github.com/hewin/machielearning-MLP
* [new branch] newBranch -> origin/newBranch
* [new branch] test -> origin/test
示例2:将远端仓mlp的各个分支代码都拉到本地仓
$ git fetch mlpFrom https://github.com/hewin/machielearning-MLP
* [new branch] newBranch -> mlp/newBranch
* [new branch] test -> mlp/test
示例3:将远端mlp仓库的test分支代码fetch到本地仓
$ git fetch mlp testFrom https://github.com/hewin/machielearning-MLP
* branch test -> FETCH_HEAD
说明2
另外可以可以用git merge或者git rebase 命令,在本地分支上合并远程分支示例1:rebase远程分支到本地分支
$ git rebase origin/newBranchCurrent branch newBranch is up to date.
示例2:merge远程分支到本地分支
$ git merge origin/newBranchAlready up-to-date.
4.git checkout
说明
切换、创建分支命令git checkout -b <分支名> <仓库名/分支名>
示例1:本地仓建立分支
$ git checkout -b newBranch origin/masterBranch newBranch set up to track remote branch master from origin.
Switched to a new branch 'newBranch'
$ git branch
master
*newBranch
示例2:从本地分支建立新分支
$ git checkout -b newBranch2 newBranchSwitched to a new branch ‘newBranch2'
$ git branch
master
newBranch
*newBranch2
示例3:切换分支
$ git checkout newBranchSwitched to branch 'newBranch'
Your branch is up-to-date with 'origin/master’.
$ git branch
master
*newBranch
newBranch2
5.git branch
说明:
查看分支(包括本地远程)命令git branch <-r / -a>
示例:不加参数查看本地分支,-r表示查看远端分支,-a查看所有分支(远端和本地)
$ git branchmaster
newBranch
*newBranch2
$ git branch -r
origin/HEAD-> origin/master
origin/master
$ git branch -a
*master
newBranch
remotes/origin/HEAD-> origin/master
remotes/origin/master
6.git pull
说明
同步远端库代码合并到本地分支$ git pull <远程主机名> <远程分支名>:<本地分支名>
示例1:将远端仓库origin的master分支与本地newBranch分支合并
$ git pull origin master:newBranchAlready up-to-date.
示例2:将远端仓库origin的master分支与默认分支合并
$ git pull origin masterFromhttps://github.com/hewin/machielearning-MLP
* branch master -> FETCH_HEAD
Already up-to-date.
示例3:以rebase模式,从远端仓库origin的master分支与newBranch分支合并
$ git pull --rebase origin master:newBranchAlready up-to-date.
7.git push
说明
s将本地分支的更新推送到远程主机,格式类似git pull(冒号前后的分支顺序相互调换)。如果远程分支名不存在,则会被新建$ git pull <远程主机名> <本地分支>:<远程分支>
示例1:将本地仓库的newBranch分支的更新推送到远端仓库origin的master分支
$ git push origin newBranch:masterEverything up-to-date
示例2:远端test分支不存在,则会在远端新建test分支
$ git push origin newBranch:testTotal 0 (delta 0), reused 0 (delta 0)
Tohttps://github.com/hewin/machielearning-MLP.git
* [new branch] newBranch -> test
$ git branch -a
master
*newBranch
remotes/mlp/master
remotes/origin/HEAD->
origin/master
remotes/origin/master
remotes/origin/test
示例3:可以指定远程默认主机
$ git push -u origin newBranchTotal 0 (delta 0), reused 0 (delta 0)
Tohttps://github.com/hewin/machielearning-MLP.git
* [new branch] newBranch -> newBranch
$ git pull
Already up-to-date.
参考:http://www.ruanyifeng.com/blog/2014/06/git_remote.html
相关文章推荐
- git使用的常见命令(一)
- git服务端、客户端安装、项目创建及常见命令使用
- git常见的使用命令介绍
- git常见场景命令使用
- Git学习——使用push命令,出现The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.警告
- Git使用常见命令的理解和记录
- 2.git学习分享--常见命令大全
- GIT学习笔记-命令基础-远程仓库的使用
- git学习--使用git pull命令"当前分支没有跟踪信息"报错问题的解决
- Git常见命令的使用
- Git使用及常见命令
- git使用(一):常见的git命令
- 【Git/Github学习笔记】ubuntu系统下使用git命令与windows下的差别
- git常见的命令使用
- git常见命令及使用
- git开发流程、常用命令及工具、TortoiseGit使用及常见问题
- git 常见使用命令
- 【Git学习笔记】git log命令使用
- git学习(常用命令的使用)
- git 命令使用常见问题