ubuntu+github配置使用
2015年底开始学习Python,接触了git这个东西,会基础的使用,顺便在github上注册了账号 https://github.com/haoxr今天重新整理一下配置使用的整个流程
1 github注册账号
本地安装git
2 本地安装git
sudo apt-get update
sudo apt-get install git
git官网下载地址:https://git-scm.com/downloads
3 初始化目录 在需要git的目录下打开终端
git init
这样就在本地建立了git仓库。可以直接操作git其他命令。
在建立本地库与github关联之前,我们需要做一些配置工作
SSH配置
4 创建SSH Key
参考廖雪峰的: https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/001374385852170d9c7adf13c30429b9660d0eb689dd43a000
在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步。
如果没有,打开Shell(Windows下打开Git Bash),创建SSH Key:邮箱地址为github邮箱地址
ssh-keygen -t rsa -C "youremail@example.com"
把id_rsa.pub内容添加到github的SSH keys页面。
5 验证是否连接成功
ssh -T git@github.com
成功结果为:
Hi haoxr! You've successfully authenticated, but GitHub does not provide shell access.
如果出现 Permission denied (publickey). 错误,参考:https://help.github.com/articles/error-permission-denied-publickey/
eval "$(ssh-agent -s)"
ssh-add
SSH警告
第一次使用Git的clone或者push命令连接GitHub时,会得到一个警告,输入yes回车即可。
The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?
建立本地库与github关联
6 本地配置github
git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"
查看配置信息
git config --list
7 本地库与github关联
git remote add origin git@github.com:haoxr/-faceDetection.git
git@github.com:haoxr/-faceDetection.git 可以在你项目中去复制
关联后可以在.git目录下的config文件中查看结果:
url = git@github.com:haoxr/-faceDetection.git
fetch = +refs/heads/*:refs/remotes/origin/*
可能会出现 the repository exists. 提示,表示你重复关联了,如果需要重置,可以直接在以上文件中删掉,也可以命令:
git remote rm origin
再重新关联
提交到github
8 添加所有文件
git add .
9 提交到本地库
git commit -m 提交内容说明
10 提交到远程库
git push -u origin master
第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,
在以后的推送或者拉取时就可以简化命令,只要本地作了提交,就可以通过命令把本地master分支的最新修改推送至GitHub
git push origin master
提交的文件有大小限制,注意大文件的移除和备份。
github的分支以及很多操作就不说了,需要用到的网上搜即可。
页:
[1]