github的使用
之前在github上注册过一个账号,后来一直没有怎么上去玩过,最近想熟悉下常用的操作,顺便学习使用git.
开始用git就出现问题了:
error: Malformed value for push.default: mytest
error: Must be one of nothing, matching, simple, upstream or current.
解决:
Matching
‘matching’ 参数是 Git 1.x 的默认行为,如果你执行 git push 但没有指定分支,它将 push 所有你本地的分支到远程仓库中对应匹配的分支。
Simple
而 Git 2.x 默认的是 simple,执行 git push 没有指定分支时,只有当前分支会被 push 到你使用 git pull 获取的代码
git config --global push.default simple
提交项目到github
在github create repos..,创建项目,在本地初始化一个git 版本库
//进入本地目录
git init
// 关联远程仓库 http方式每次要输入密码 ssh不用
git remote add origin https://github.com/chlss/Android-PCMDecorder.git
git remote add origin git@github.com:chlss/Android-PCMDecorder.git
// 提交代码到远程master分支
git push origin master
// 从远程来代码下来,保证两端同步
git pull origin master
pull 代码报错
remote: Anonymous access to chlss/Android-PCMDecorder.git denied.
fatal: Authentication failed for 'https://github.com/chlss/Android-PCMDecorder.git/'
没有权限,需要SSH验证(SSH是一种网络协议,用于计算机之间的加密登录):
ssh-keygen -t rsa 生成公钥 3个回车
在C:\Users\user\.ssh 会生成3个文件
id_rsa
id_rsa.pub
known_hosts
将id_rsa.pub的内容添加到github上,这样本地id_rsa密钥才能与 GitHub 上的 id_rsa.pub 公钥进行配对,授权。
拷贝id_rsa.pub的内容到github ssh
完成
测试
ssh -T git@github.com
// 验证成功
Hi chlss! You've successfully authenticated, but GitHub does not provide shell access.
重新提交
git pull origin master
// 成功
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 589 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To git@github.com:chlss/Android-PCMDecorder.git
232eb86..9928a08 master -> master
进过以上不走就可以向github提交自己的项目了!
git配置命令
// 查看配置 全局
git config --global -l
git config --list
// 设置用户名邮箱,让远程可见
git config --global user.name "aaa"
git config --global user.email "bbb"