git使用
Git 不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等。
1.Git 安装配置
Debian/Ubuntu Git 安装命令为:
$ apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
$ apt-get install git
$ git --version
Centos/RedHat 安装命令为:
$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
$ yum -y install git-core
$ git --version
Windows 平台上安装
下载https://npm.taobao.org/mirrors/git-for-windows/
2.Git 配置
Git 提供了一个叫做 git config 的工具,专门用来配置或读取相应的工作环境变量。
通过命令git config -h可以查看帮助,设置生效范围有:
usage: git config [options]
Config file location
--global use global config file
--system use system config file
--local use repository config file
-f, --file <file> use given config file
--blob <blob-id> read config from given blob object
配置含义解释:
global 即是读/写当前用户全局的配置文件(~/.gitconfig 文件,属于某个计算机用户)
system 即是读写系统全局的配置文件(/etc/gitconfig 文件,属于计算机)
local 即是当前 clone 仓库 的配置文件(位于 clone 仓库下 .git/config)。
配置个人的用户名称和电子邮件地址:
$ git config --global user.name "runoob"
$ git config --global user.email test@runoob.com
要检查已有的配置信息::
$ git config --list
3.git 配置 https和ssh 免密码登录
https通过记住账号密码免登,ssh通过校验生成的密钥免登。 通常都用ssh校验。
https免密配置方法:
git config --global credential.helper store
[credential]
helper = store
输入一次账号密码后第二次就会记住账号密码。
ssh免密配置方法
git init
git config --global user.name '用户名'
git config --global user.email '用户邮箱'
执行生成公钥和私钥的命令:
ssh-keygen -t rsa -C "用于识别密钥的邮箱地址"
执行查看公钥的命令:
cat ~/.ssh/id_rsa.pub
将上面的id_rsa.pub内容复制粘帖到gitee.com或github.com的"setting--SSH keys"中
有时需要检查ssh的配置文件:
vi ~/.ssh/config
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
4. git clone 项目
https方式: git clone https://gitee.com/user_name/project_name.git
ssh方式: git clone git@gitee.com:user_name/project_name.git
5. git 提交项目
git status 查看状态
git add . 添加所有的修改文件
git status 查看状态
git commit -m '备注信息' 添加备注
git push origin master 提交到master分支上
5. git本地项目代码上传至远程仓库操作
建立一个本地仓库目录test
mkdir test
进入本地仓库目录
cd test
初始化:
git init
将本地仓库与已经存在的远程仓库(通过web进行创建)进行关联:
git remote add origin git@gitee.com:user_name/remote_project.git
操作提交master步骤:
git add .
git status
git commit -m '备注信息'
git push origin master
评论已关闭