一.下载安装git,https://git-scm.com/download/(官网)
二.一般有git GUI 以及git bash,git GUI图形化界面毕竟在功能上还是具有一定的局限性,所以在git bash中通过命令行学习git的使用
1.设置用户信息
git config --global user.name "username" //此处是github上注册的用户名
git config --global user.email "email" //此处是github上注册时使用的邮箱
2.获取秘钥
ssh-keygen -t rsa -C "email"//填写email地址
打开本地磁盘.\ssh\id_rsa.pub文件,该内容为刚刚生成的秘钥,该文件一般在C:\user\admin\.ssh\id_rsa.pub,用记事本打开即可;
将记事本打开的文件复制到github中的settings/SSH and GPGkeys 中,选择new SSH key,其中title任意,复制完成后,点击add SSH key
测试SSH连接的github服务器:
ssh -T git@github.com
Hi (username)! You've successfully authenticated, but GitHub does not provide shell access.获得该提示,说明连接成功。
3.远程操作(此处先在github中新建了一个repsitories----hello)
1)先clone(从repositories中clone到本地):git clone git@github.com:username/hello.git 即可将该repositories中的文件都clone到指定路径中
2)再push(push到repositories中):git add . 可以添加要add的文件,“.”表示添加该目录下的所有文件,
git commit -m 'add files' //提交更新
git push origin master //push到远程master上
注意,将本地文件push时,添加readme
3)直接push:在本地创建hello文件夹,右击文件夹用git init命令初始化git环境,然后添加文件,push时在commit后多执行一步:
git remote add origin git@github.com:username/hello.git
4.如果在其他用户的repositories中执行远程操作,则建立的连接为HTTPS
点击clone or download按钮,复制连接,在git bash中输入
git clone https://****** 即可clone到本地