GIT基础

1、配置用户和邮箱信息

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

2、查看配置信息

git config --list

3、初始化仓库

$ git init

4、克隆

git clone url

5、从远程仓库更新项目
git pull <远程主机名> <远程分支名>:<本地分支名>

git pull

6、代码提交

//查看工作区代码相对于暂存区的差别
git status 
//将当前目录下修改的所有代码从工作区添加到暂存区 . 代表当前目录
git add . 
//将缓存区内容添加到本地仓库
git commit -m ‘注释’ 
//设置远程仓库名为origin
git remote add origin https://github.com/apache/dubbo.git
//将本地版本库推送到远程服务器, origin是远程主机,master表示是远程服务器上的master分支
git push origin master 
例如:$ git push origin dev

7、获取远程分支列表

git ls-remote

8、建立本地到上游(远端)仓的链接

//其中,origin/remote_branch是你本地分支对应的远程分支;your_branch是你当前的本地分支。
git branch --set-upstream-to=origin/remote_branch  local_branch

9、如何使用.gitignore文件删除掉已经提交的文件
如果你的文件已经提交,而此时你才发现忘了添加.gitignore文件,不用担心,有办法,只要按照下面的步骤一一来做就可以

//1、首先需要将本次修改的代码提交
git commit -a;
//2、按顺序依次执行如下命令:
git rm -r --cache .
git add .
git commit -m ".gitignore now work"
git push
//提交到远程仓库,会发现.gitignore文件起作用了。

10、在线学习GIT
gitbook: https://git-scm.com/book/en/v2

11、GIT下载
https://github.com/git/git/releases

12、查看版本提交历史

git log

 13、将本地分支推送到远程指定分支

git push git_url <local_branch>:<remote_branch>

#当远程分支不存在时,将本地分支推送到远端,此时会在远端创建新分支
#新建本地分支
$ git checkout -b  “分支名称”
#查看是否创建成功以及目前在哪个分支
$ git branch       
#本地推送到远程
$ git  push -u origin "分支名称"

14、无法提交时

$ git push
To https://github.com/apache/dubbo.git
 ! [rejected]        dev -> dev (non-fast-forward)
error: failed to push some refs to 'https://github.com/apache/dubbo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

解决方法:强制提交

$ git push -f origin dev

15、拉取指定分支

1、若git clone之后想拉取某个指定分支:先git pull ,然后git checkout 指定分支名称

2、若git clone之后想拉取某个指定分支:先git fetch origin 分支名称,然后git checkout 指定分支名称

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值