建立仓库
下载git:
地址:git
按提示安装即可,不多做介绍。安装完成后在文件夹下点击右键会出来Git Bash Here,点击打开。
输入命令 git init在本地建立一个仓库,
新建任意一个文件,在git bash here中输入命令 git status查看文件状态
相比于svn不同的地方就是git有一个暂存区的概念,输入命令git add * 或git add {文件名}就是再往版本库中添加文件,
往版本库中添加文件时先是把文件添加到了暂存区,在输入命令git commit -m {文字介绍或修改注释},才会把暂存区的内容提交到当前分支master(创建git版本库时会自动创建一个唯一分支master)
git init -> 新建文件 ->git status -> git add * 或 git add 文件名 ->git commit -m 修改注释
关联本地仓库
登陆github,建立一个新的远程仓库,并复制仓库地址
在本地仓库中打开git bash here,输入命令git remote add origin 远程仓库地址,origin即为远程仓库名称,这是git默认的叫法
输入命令git push -u origin master,把前面已经新建好并提交的文件可以上传到远程库中,可以刷新网页查看
SSH警告
第一次使用git的clone或push命令链接github时,会得到一个警告
The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?输入yes即可
关于SSH key
在用户目录下有一个.ssh目录,里面有id_rsa和id_rsa.pub俩个文件,这俩个就是SSH Key的密钥对
如果没有这俩个文件打开git bash输入命令ssh-keygen -t rsa -C “你的邮箱地址”,就会生成密钥对
登陆github,打开设置,点击选项SSH and GPG keys,add new SSH Key,title随便起个名字,再把id_rsa.pub中的内容粘贴到Key中,点击Add SSh key。
关于bug
$ git push -u origin master
To git@github.com:fansining/vueBox.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:fansining/vueBox.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.