一: ubuntu密钥连接github
1) git config --global user.name "username"
2) git config --global user.email "username@163.com"
3) ssh-keygen -t rsa -b 4096 -C "username@163.com" -f ~/.ssh/id_rsa_github
4) vi id_rsa_github.pub
5) 复制id_rsa_github.pub 中内容到github, 或者cat id_rsa_github.pub (这样复制的没有空格)
Settings/SSH and GPG keys下,点击 SSH 公钥,标题栏可以随意输入,公钥栏把刚才复制的内容粘贴进去
6)ssh -i ~/.ssh/id_rsa_github -T git@github.com
或者 ssh -T git@github.com
成功!!
如果不成功,可以尝试,
ssh-add ~/.ssh/id_rsa_github
如果出现:Could not open a connection to your authentication agent.
使用 eval "$(ssh-agent -s)", 再用指令ssh-add ~/.ssh/id_rsa_github
(指令ps aux | grep ssh-agent和ps aux | grep ssh-agent | grep -v grep查看已有的agent和正在运行的agent)
二:push代码到github
git init
git add .
git remote add origin git@github.com:nnzhangup/MultiView.git (最后是github 中ssh上复制的)
如果已经存在origin,要把orign删掉 git remote rm origin
再用git remote add origin git@github.com:username/projectname.git
git push origin master
git status(查看仓库状态)
git branch(查看branch,带*号的是活跃的branch)
git branch -d new_branch1 删除branch
git checkout branch_name (将活跃branch切换为branch_name)