代码管理在日常开发中是非常重要的,现在主要使用的代码管理工具就有svn和git。今天就记录下怎么用msysGit管理GitHub上的代码。
一、在GitHub上注册账号,然后创建代码库
1.进入GitHub网址:https://github.com注册即可
2.创建代码库
2.1进入github首页
2.2点击右上角创建代码库
二、下载并安装msysGit客户端
1.下载网址:https://git-for-windows.github.io/
2.安装msysgit
三、使用msysGit连接GitHub
1.打开刚安装的msysGit,点击"Git Bash.exe"
2.为Github账户设置SSH key
2.1产生ssh key
输入命令:$ ssh-keygen -t rsa -C "你的邮箱地址"
然后回车,接着输入密码,回车,再次输入密码,回车,就生成了ssh key
产生的key默认在/c/Users/xxx/.ssh/目录下
id_rsa.pub里面的内容即为ssh key,可用记事本打开。
2.2负责ssh key到github上
1.登录github
2.点击右上方的settings图标
3.选择 SSH key
4.点击 Add SSH key
5.填写名称和SSH key,最后提交,添加成功
2.3测试连接github
回到msysgit,输入命令:ssh -T git@github.com
接着输入密码
四、使用msysGit管理代码库
1.从github同步代码到本地
从github页面中获取代码库地址
在msysgit终端输入命令:git clone git@github.com:langxinlen/NDKdemo.git
2.提交代码到github
2.1如果使用HTTPS:
Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/guochy2012/test.git
git push -u origin master
Push an existing repository from the command line
git remote add origin https://github.com/guochy2012/test.git
git push -u origin master
2.2如果采用SSH:
Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:guochy2012/test.git
git push -u origin master
Push an existing repository from the command line
git remote add origin git@github.com:guochy2012/test.git
git push -u origin master
使用HTTPS需要每次输入密码,SSH则不用,但SSH需要配置密钥 。
提交代码都是先使用命令 git add XXX 添加该文件或者文件夹
然后使用命令 git commit -m "提交说明" 把该操作提交到代码库
最后使用git push 把本地的提交,提交到github上