1、首先去git官网下载安装git https://git-scm.com/downloads
2、git安装成功后在桌面右键会有Git Bash Here,打开Git Bash Here命令行工具设置当前库的用户名和邮箱
git config user.name "username"
git config user.email "xxx@163.com"
查看当前库的用户名和邮箱命令:
git config user.name
git config user.email设置当前库的用户名和密码
git config user.name “username”
git config user.email “xxx@163.com”设置全局的用户名和密码
git config --global user.name “username”
git config --global user.email “xxx@163.com”
注:尽量将git客户端的用户名、邮箱和github账号的用户名、邮箱设置一致
3、打开Git Bash Here命令行工具,创建SSH Key
ssh-keygen -t rsa -C "xxx@163.com"
4、使用邮箱注册一个GitHub账号 https://github.com
5、打开.ssh下的id_rsa.pub文件,复制key,登录GitHub,打开"SSH Keys"页面,把key粘贴进去
6、测试ssh key是否配置成功
ssh -T git@github.com
如果出现You’ve successfully authenticated, but GitHub does not provide shell access ,表示成功连上github
7、在github中新建一个远程仓库
8、在本地新建一个文件夹test,从远程(github)克隆一份到本地
git clone https://github.com/xxx/test.git
如果直接提交本地的项目先初始化
git init
9、在test目录下开始进行项目搭建,搭建完成后提交到本地仓库
git add .
添加当前目录的所有文件到暂存区
git commit -m '备注'
将暂存区文件提交到本地仓库
10、查看test目录下文件是否全部提交
git status
11、关联远程仓库
git remote add origin https://github.com/xxx/test.git
12、推送master分支的所有内容
git push -u origin master
第一次使用加上了-u参数,是推送内容并关联分支,下次只要本地作了提交,就可以直接执行命令:
git push origin master
git常用查看/创建/切换/合并分支命令:
查看当前所在分支
git branch
查看远程的所有分支以及自己当前所在的分支
git branch -a
在本地创建分支
git branch branchName
切换到新建分支
git checkout branchName
在本地创建分支并切换到新建分支
git checkout -b branchName
切换到远程服务器上的命名为branchName分支
git checkout --track origin/branchName
本地分支关联远程分支
git branch --set-upstream localBranchName origin/branchName